繁体   English   中英

MySQLi编写的语句没有返回任何内容

[英]MySQLi prepared statement not returning anything

我试图从文字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而不是。

尝试调用$stmt->store_result(); execute()调用之后。
执行后结果尚未存储在内存中,您将需要获取所有行或调用store_result()以获取num_rows变量以显示受影响的实际行数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM