編輯:錯誤2014:命令不同步(偏偏一個服務器,但不是另一個)
好了,所以,我做了一些更多的測試,發現它是存儲過程的混亂一切。但我不知道爲什麼存儲過程搞亂了。有關詳細信息,請參閱本帖子下的第一條評論
/編輯
好了,所以,我有這所學校的項目,我一直都在用我的筆記本電腦作爲服務器。但是,如果不將它放在學校的服務器上,我無法提交。我的講師終於讓我獲得了它,我終於能夠開始在那裏遷移我的項目。
在修復了一些較小的問題(如默認字符集不匹配和大小寫敏感性問題)之後,這個特殊問題就出現了,並且讓我難倒了。我花了幾個小時瀏覽我的代碼,查看PHP文檔,並修改我的代碼以打印出調試文本的牆,最後用盡可能少的代碼重新生成了該錯誤。
這裏是PHP代碼:
<?php
define("HOST", "someHost");
define("USER", "someUser");
define("PASS", "somePass");
define("DB" , "someDB");
$conn = mysqli_connect(HOST, USER, PASS, DB);
$stmt1 = $conn->stmt_init();
if (!$stmt1->prepare("CALL P_Topics_Get(33);")) {//If I uncomment this, I get an error when trying to prepare $stmt2
//if (!$stmt1->prepare("SELECT * FROM Topics WHERE id = 33;")) { //If I uncomment this, I DON'T get an error anywhere
//if (!$stmt1->prepare("SELECT 0, 'name', 1, 2, 3;")) {//If I uncomment this, I DON'T get an error anywhere
echo "Failed to prepare 1: " . $conn->errno . ", " . $conn->error;
exit;
}
if (!$stmt1->execute()) {
echo "Failed to execute 1: " . $conn->errno . ", " . $conn->error;
exit;
}
if (!$stmt1->store_result()) {
echo "Failed to store 1: " . $conn->errno . ", " . $conn->error;
exit;
}
$stmt1->bind_result($id, $name, $step, $decAmt, $maxAmt);
if (!$stmt1->fetch()) {
echo "Failed to fetch 1: " . $conn->errno . ", " . $conn->error;
exit;
}
echo "$id, $name, $step, $decAmt, $maxAmt<br>";
$stmt1->free_result();
$stmt1->close();
$stmt2 = $conn->stmt_init();
if (!$stmt2->prepare("SELECT 2;")) {
echo "Failed to prepare 2: " . $conn->errno . ", " . $conn->error;
exit;
}
if (!$stmt2->execute()) {
echo "Failed to execute 2: " . $conn->errno . ", " . $conn->error;
exit;
}
if (!$stmt2->store_result()) {
echo "Failed to store 2: " . $conn->errno . ", " . $conn->error;
exit;
}
$stmt2->bind_result($val2);
if (!$stmt2->fetch()) {
echo "Failed to fetch 2: " . $conn->errno . ", " . $conn->error;
exit;
}
echo "Val 2: " . $val2 . "<br>";
$stmt2->free_result();
$stmt2->close();
echo "success";
?>
P_Topics_Get()是從表中簡單的SELECT語句:
SELECT
*
FROM
Topics t
WHERE
t.id = topicId;
所以..是啊。這在我的本地主機上運行,沒有錯誤,但在學校的機器上攪亂了一切。這是我第一次遇到2014年的錯誤..而且只是2013年! (/笑話)
任何人都知道這是怎麼回事?
我將這個if語句添加到測試中:if(!$ stmt1-> prepare(「SELECT * FROM Topics WHERE id = 33;」)){//如果我取消註釋,我不會在任何地方得到一個錯誤,這個if語句(基本上就是存儲過程)它不會崩潰或在任何地方顯示錯誤。我可以得出結論,問題是存儲過程..不知何故。我現在才確定爲什麼。 –