我在 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/