我正在尝试做如下预备陈述:
$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();
我收到以下错误:
Fatal error: Call to a member function bind_param() on a non-object in /path/to/script.php on line 97
添加`和'给我
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM `table` WHERE `from` = '?' && `to` = '?' LIMIT 1");
以及
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
显然BIND变量的数量与?的数量相匹配?分数。我已尝试添加和删除“和”的所有组合无济于事。这份准备好的陈述有什么问题?我可以用一个条件做一个SELECT就好了,但它有多个抱怨。
答案 0 :(得分:4)
不需要引用占位符(?
)。
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM `table` WHERE `from` = ? && `to` = ? LIMIT 1");