我正在使用 mysqli 函数(mysqli_connect, mysqli_select_db, mysqli_query)
来调用 1 个选择查询和 2 个存储过程。
似乎当我多次使用相同的$connection
(由返回)时,我收到以下错误消息:mysqli_connect
"Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in..."
下面是我的代码:
<?php
$server="localhost";
$user="user";
$pass="pass";
$db="db";
$connection=mysqli_connect("$server","$user","$pass");
mysqli_select_db($connection, "$db") or die('Unable to select database.');
//First SELECT using $connection
$query=mysqli_query($connection, "SELECT item_name FROM items ORDER BY item_name DESC");
While ($result=mysqli_fetch_array($query,MYSQL_NUM))
{
$complete_result[] = $result[0];
$total_rows = $total_rows + 1;
}
//CALL to first sp using $connection
$query2 = mysqli_query($connection, "CALL sp_check_edits_remaining()");
while ($row2 = mysqli_fetch_array($query2, MYSQL_ASSOC)) {
$edits_remaining = $row2['edits_remaining'];
} // End while
//CALL to second sp using $connection
$query3 = mysqli_query($connection, "CALL sp_edit_data");
while ($row3 = mysqli_fetch_array($query3, MYSQL_ASSOC)) {);
$edits_id = $row3['id'];
} // End while
?>
就像我描述的那样,当我调用第二个 sp 时,上面的代码给了我上面提到的错误消息。(请注意,连接永远不会关闭。)
但是,当我创建另一个连接并将其提供给第二个 sp 调用时,此错误就会消失。这显示在下面的代码中
$connection2=mysqli_connect("$server","$user","$pass");
mysqli_select_db($connection2, "$db") or die('Unable to select database.');
//CALL to second sp using $connection
$query3 = mysqli_query($connection2, "CALL sp_edit_data");
while ($row3 = mysqli_fetch_array($query3, MYSQL_ASSOC)) {
$edits_id = $row3['id'];
} // End while
谁能帮助我为什么会出现这种意外行为?谢谢,提前!