dsk95913 2012-04-04 18:25
浏览 29
已采纳

在查询中获取别名的结果

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.

  • 写回答

1条回答 默认 最新

  • dougu5886 2012-04-04 18:30
    关注

    Try this

    Mysqli::query does not have fetch_object method it would return mysqli_result::fetch_assoc for more information please look at

    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

    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

    :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃