PHP 5.2.6的mysqli_stmt_get_result替代 [英] mysqli_stmt_get_result alternative for php 5.2.6

查看:63
本文介绍了PHP 5.2.6的mysqli_stmt_get_result替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是php专家,我开发了一个小型服务来查询mysql数据库.

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

但是我是用php 5.4开发的,然后发现我的虚拟主机计划具有5.2.6,因此对于一些未定义的函数,我遇到的问题很少.

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.

具体来说,在这种情况下,如何解决> 5.3上可用的mysqli_stmt_get_result未定义函数?这是代码:

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;

  }

关键是我正在使用一条准备好的语句,由于缺乏php知识,我发现没有其他方法可以解决该问题,而无需重写整个脚本.

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.

推荐答案

mysqli_stmt_get_result函数仅适用于PHP 5.3或更高版本.对于您的PHP 5.2.x版本(此功能不再受支持)不存在.

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.).

替代方法是对变量绑定使用 mysqli_stmt_bind_result .

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.

之所以引入mysqli_stmt_get_result函数,是因为有人认为用您的方式来获得数组会更容易.

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.

这篇关于PHP 5.2.6的mysqli_stmt_get_result替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆