我正在尝试按如下方式执行准备好的语句:
$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,但在多个条件下它会报错。
最佳答案
占位符(?
)不需要被引用。
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM `table` WHERE `from` = ? && `to` = ? LIMIT 1");
关于php - MySQLi 多个条件,有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8956185/