1 php mysql oop prepared-statement
我想检查一下if ($numRows >= 1)它应该返回一些东西。
当我使用时$con->mysql("{QUERY}"),它有效。
但当我使用时$stmt = $con->prepare("{QUERY}"),它不起作用。
有人有线索吗?
<?php
if ($result = $con->query("SELECT username FROM users WHERE username = 'test'")) {
$numRows = $result->num_rows;
echo $numRows;
}
?>
Run Code Online (Sandbox Code Playgroud)
结果:1
<?php
$name = 'test';
$stmt = $con->prepare("SELECT username FROM users WHERE username = ?");
$stmt->bind_param('s', $name);
$name = 'test';
$stmt->execute();
$numRows = $stmt->num_rows;
echo $numRows;
?>
Run Code Online (Sandbox Code Playgroud)
结果:0
SELECT在调用该方法之前,您需要传输查询的结果集->num_rows()。
// your code
$stmt->execute();
$stmt->store_result();
$numRows = $stmt->num_rows;
echo $numRows;
Run Code Online (Sandbox Code Playgroud)
这是参考:
| 归档时间: |
|
| 查看次数: |
3255 次 |
| 最近记录: |