duanou2526 2012-10-21 09:04
浏览 97
已采纳

php 5.2.6的mysqli_stmt_get_result替代方案

I am not an expert of php, I developed a small service which query a mysql db.

However I developed with php 5.4, and then discovered that my web hosting plan has 5.2.6, so I am having few problems with some undefined function.

Specifically, in this case, how can I solve the mysqli_stmt_get_result undefined function available on > 5.3 ? Here is the code:

  $stmt = mysqli_prepare($con,$db_query);

  if($stmt) {

     mysqli_stmt_bind_param($stmt,'ss',$after,$lang);
     mysqli_stmt_execute($stmt);
     $result = mysqli_stmt_get_result($stmt); // <-- getting undefined error here !!!

     $updated = array();
     $deleted = array();

     while($row = mysqli_fetch_assoc($result)) {

        if($row['status']==1) {
           array_push($updated,$row);
        } else {
           $cardName=$row['cardName'];
           $cardStatus=$row['status'];
           $cardId=$row['cardId'];
           $language=$row['language'];
           array_push($deleted,array(
                    'cardName'=>$cardName,
                                    'status'=>$cardStatus,
                                    'cardId'=>$cardId,
                                    'language'=>$language
                               )
           );
        }
     }

     $response = array(
        'cards'=>array(
           'updated'=>$updated,
           'deleted'=>$deleted
        )
     );

     $json = json_encode($response);
     mysqli_close($con);
     echo $json;

  }

The point is that I am using a prepared statement, due to my lack of php knowledge I found no other way of resolving the issue without rewriting the whole script.

I thought that some of you may have a simple and easy solution.

  • 写回答

3条回答 默认 最新

  • dongse5408 2012-10-21 12:51
    关注

    The mysqli_stmt_get_result function is PHP 5.3 or greater only. It does not exist for your PHP 5.2.x version (which is not supported any longer btw.).

    The alternative is to use mysqli_stmt_bind_result with variable bindings.

    In your concrete example this has even the benefit that you do not need to assign the array members to variables, because you can bind the variables directly.

    The mysqli_stmt_get_result function was introduced because someone thought this would stand in your way and getting an array would have been easier.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加