我有以下查询:
$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使用别名的文章。
如果有人可以告诉我我做错了什么,那就太好了。非常感谢。答案 0 :(得分:2)
试试这个
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'" );
}
}
由于
:)