I am trying to do prepared statements as follows:
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM table WHERE from = '?' && to = '?' LIMIT 1");
$stmt->bind_param('ii', $fromId, $toId);
$stmt->execute();
$stmt->bind_result($db_offeredAlready);
$stmt->fetch();
$stmt->close();
I get the following error:
Fatal error: Call to a member function bind_param() on a non-object in /path/to/script.php on line 97
Adding ` and ' gives me
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM `table` WHERE `from` = '?' && `to` = '?' LIMIT 1");
and the following
Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /path/to/script.php on line 97
Obviously the number of BIND vars match the number of ? marks. I have tried all combinations of adding and removing ` and ' to no avail. What's wrong with this prepared statement? I can do a SELECT with one condition just fine, but it complains with multiple.