我使用mysqli函數(mysqli_connect, mysqli_select_db, mysqli_query)
來調用1個select查詢和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
任何人都可以請幫我爲什麼這種意想不到的行爲? 非常感謝!
太好了。謝謝... – Sayka