我正在尝试从文字query
调用过渡到准备好的语句。
我在课堂上有以下功能:
public function read ($identifier) {
$stmt = static::$mysqli->prepare('SELECT * FROM `table` WHERE `id` = ?;');
$stmt->bind_param('i', $identifier);
$stmt->execute();
var_dump($stmt->num_rows);
}
我从 phpMyAdmin 知道数据库中有 id 为 1 的行,但如果我调用read(1);
,num_rows
则为 0。
但是,如果我使用这个逻辑:
public function read ($identifier) {
$result = static::$mysqli->query('SELECT * FROM `table` WHERE `id` = '.(int) $identifier.';');
var_dump($result->num_rows);
}
相反,我得到 1。