简体   繁体   English

获取查询中别名的结果

[英]fetch a result of an alias in a query

i have the following query:我有以下查询:

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

and get the following errormessage:并得到以下错误信息:

Fatal error: Call to undefined method mysqli::fetch_object()  

that relates to this line:与这一行有关:

while ($row = $db->fetch_object()){  

i also was trying to use:我也试图使用:

while ($row = $db->fetch_object($timecheck)){  

without any success.没有任何成功。 So in the manual is nothing written about how to use an alias by fetch-method.所以在手册中没有写任何关于如何通过获取方法使用别名的内容。

it would be great if there is someone who could tell me what am i doing wrong.如果有人可以告诉我我做错了什么,那就太好了。 thanks a lot.多谢。

Try this试试这个

Mysqli::query does not have fetch_object method it would return mysqli_result::fetch_assoc for more information please look at Mysqli::query没有fetch_object方法,它会返回mysqli_result::fetch_assoc有关更多信息,请查看

http://www.php.net/manual/en/mysqli.query.php http://www.php.net/manual/en/mysqli.query.php

http://php.net/manual/en/mysqli-result.fetch-assoc.php http://php.net/manual/en/mysqli-result.fetch-assoc.php

http://www.php.net/manual/en/mysqli-result.fetch-object.php http://www.php.net/manual/en/mysqli-result.fetch-object.php

Example:例子:

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

Thanks谢谢

:) :)

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

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