php - MySQLi multi_query next_result 始终返回 1

标签 php mysql sql mysqli

我在 MySQL 中有一个简单的存储过程。这是代码。

CREATE DEFINER = 'root'@'chl.rontel.ru' PROCEDURE `test`()
    NOT DETERMINISTIC
    CONTAINS SQL
    SQL SECURITY DEFINER
    COMMENT ''
begin
    select * from `mbus_log` where serial_num='12';
    select count(*) from mbus_log;
end;

在 MySQL 的 SQL 管理器中,它返回 6 行表和总行数 - 293。 所以我想从 PHP 获取这个值。这是 PHP 代码:

    public $mysqli;

...
    $this->mysqli=new mysqli($this->mysql_host,$this->mysql_user,$this->mysql_password,$this->mysql_db);
    if ($this->mysqli->connect_error) 
    {
        die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
    }
    $this->mysqli->query("SET NAMES UTF8");
...
        $result= $this->mysqli->multi_query("call test();");
        $getReadingsByAddress=$this->mysqli->store_result();
        if ($this->mysqli->errno) 
        {
            die('Select Error (' . $mysqli->errno . ') ' . $mysqli->error);
        }
        else
        {
            while( $row = mysqli_fetch_object($getReadingsByAddress) )
            { 
                 $res.="<tr><td><a class='serialLink' href='./'>".$row->serial_num."</a></td><td>".$row->value."</td></tr>"; 
            } 
        }
        $getReadingsByAddress->close();
        $res.=$this->mysqli->next_result();

$mysqli->store_result() 工作正常并返回正确的值,但 next_result 方法每次都返回 1。我也尝试这样做:

$result= $this->mysqli->multi_query("call test(); SELECT COUNT(*) from mbus_log;");

下一个结果也返回 1。另外,当我尝试 var_dump($this->mysqli->next_result()); 它返回 bool(false),但是 more_results 方法返回 true 有什么问题?

最佳答案

我唯一的想法是尝试给 count(*) 一个列名 IE count(*) AS MyCount。

关于php - MySQLi multi_query next_result 始终返回 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661868/

相关文章:

php - Wordpress/SQL 中 Orderby 默认为 DESC

php - MySQL 返回 -0001 作为年份

MySql - 按日期排序,然后按时间排序

php - 检查文件系统文件与数据库的一致性

MySQL获取尚未使用的优惠券

c# - 开始使用C#/ASP.NET学习SQL

mysql - SQL Select 其中 user1 有多个,而 user2 没有

javascript - Json 编码 数组与仅转换为数组的对象的混合

php - Doctrine :按与列同名的别名排序

php - CakePHP - 保存日期字段时出错