Php MySQLi准备的语句没有返回任何内容
我正在尝试从literalPhp MySQLi准备的语句没有返回任何内容,php,mysql,mysqli,prepared-statement,sqlbindparameter,Php,Mysql,Mysqli,Prepared Statement,Sqlbindparameter,我正在尝试从literalquery调用转换为准备好的语句 我在班上有以下功能: public function read ($identifier) { $stmt = static::$mysqli->prepare('SELECT * FROM `table` WHERE `id` = ?;'); $stmt->bind_param('i', $identifier); $stmt->execute(); var_dump($stmt-&
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)代码>,行数
为0
但是,如果我使用此逻辑:
public function read ($identifier) {
$result = static::$mysqli->query('SELECT * FROM `table` WHERE `id` = '.(int) $identifier.';');
var_dump($result->num_rows);
}
我得到了1。尝试调用$stmt->store_result()调用execute()
后的code>。
执行后,结果尚未存储在内存中,您必须获取所有行,或者调用num\u rows
变量的store\u result()
,以显示受影响的实际行数