0

我有以下查询:

$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 使用别名。

如果有人能告诉我我做错了什么,那就太好了。多谢。

4

1 回答 1

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'" );
    }
} 

谢谢

:)

于 2012-04-04T18:30:38.780 回答