Reputation: 35
$stmt = $mysqli->prepare("SELECT vin FROM jobs WHERE out between ? and ?");
$stmt->bind_param('ss', $startday, $endday);
$startday = '2013-01-01';
$endday = '2013-12-31';
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($vin);
echo $vin;
the code above shoots out this error the query work if i remove the between part of the statment. i tried enclosing the column name in brackets but that kills the query too so i had to remove them. seems the problem is with the between clause i just might not know how to use it. help please
Fatal error: Call to a member function bind_param() on a non-object
Upvotes: 3
Views: 2182
Reputation: 263813
The problem is not on the BETWEEN
clause but theuse of reserved keyword OUT
as your column name. There are two ways to keep this work,
One is by wrapping it with backticks,
$stmt = $mysqli->prepare("SELECT vin FROM jobs WHERE `out` between ? and ?");
and the other is by supplying an ALIAS
on the table, and using it with the column name.
$stmt = $mysqli->prepare("SELECT vin FROM jobs a WHERE a.out between ? and ?");
Upvotes: 3