我有以下查询:
$timecheck = $db->query("SELECT (B <= NOW()) AS var FROM table1 WHERE x='$x'");
while ($row = $db->fetch_object()){
if ($row->var != 0){
$updatestatus = $db->query("UPDATE table2 SET abc='1' WHERE x='$x'");
}
}
并得到以下错误消息:
Fatal error: Call to undefined method mysqli::fetch_object()
与此行相关:
while ($row = $db->fetch_object()){
我也尝试使用:
while ($row = $db->fetch_object($timecheck)){
没有任何成功。所以手册中没有写任何关于如何通过 fetch-method 使用别名的内容。
如果有人能告诉我我做错了什么,那就太好了。非常感谢。
最佳答案
试试这个
Mysqli::query
没有 fetch_object
方法,它会返回 mysqli_result::fetch_assoc
有关更多信息,请查看
http://www.php.net/manual/en/mysqli.query.php
http://php.net/manual/en/mysqli-result.fetch-assoc.php
http://www.php.net/manual/en/mysqli-result.fetch-object.php
示例:
$result = $db->query ( "SELECT (B <= NOW()) AS var FROM table1 WHERE x='$x'" );
while ( $row = $result->fetch_object () ) {
if ($row->var != 0) {
$updatestatus = $db->query ( "UPDATE table2 SET abc='1' WHERE x='$x'" );
}
}
谢谢
:)
关于php - 获取查询中别名的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10017101/