下面的代碼在我的本地服務器上運行時沒有任何問題。但是,當我嘗試在預期的服務器上運行它時,我的兩個查詢不起作用 - 它們不是INSERT
,因爲它們應該是這樣。我標記了兩個不支持評論的查詢,其餘的都有效。目標服務器在PHP 5.6.30-0 + deb8u1上運行。插入查詢在服務器上不起作用
UPDATE:感謝aynber,我已經跟蹤誤差。這是第一個查詢錯誤:準備好的聲明\「editRecord \」不存在」我不明白爲什麼這個工程的本地服務器上,但不能在預期的一個
更新2:之間錯誤準備的語句和執行:語法錯誤處或附近\ 「ON \」 \ n線段3:
case "editRecord":
$id = openPandoraBox(post("id"));
$tutorAbsence = post("tutorAbsence");
$clientAbsence = post("clientAbsence");
if($tutorAbsence == "1") {
if(post("tutor") != "0") {
// ------------this query does not work.-----------
$absUpsSql = "INSERT INTO tutorabsence(id, tutorid, reason)
VALUES ($1, $2, $3)
ON CONFLICT (id)
DO UPDATE SET tutorid=$2, reason=$3";
$absUpsPrep = pg_prepare($conn, 'editRecord', $absUpsSql);
$absUpsQry = pg_execute($conn, 'editRecord',
array($id, post("tutor"), post("tutorreason"))
);
} else {
$tutorAbsence = "0";
};
} else {
$absDelSql = "DELETE FROM tutorabsence WHERE id=$1";
$absDelPrep = pg_prepare($conn, 'absDel', $absDelSql);
$absDelQry = pg_execute($conn, 'absDel', array($id));
};
if($clientAbsence == "1"){
if(post("client") != "0") {
// ------------this query does not work.-----------
$absUpsSql = "INSERT INTO clientabsence(id, clientid, reason)
VALUES ($1, $2, $3)
ON CONFLICT (id)
DO UPDATE SET clientid=$2, reason=$3";
$absUpsPrep = pg_prepare($conn, 'absUps', $absUpsSql);
$absUpsQry = pg_execute($conn, 'absUps',
array($id, post("client"), post("clientreason"))
);
} else {
$clientAbsence = "0";
};
} else {
$absDelSql = "DELETE FROM clientabsence WHERE id=$1";
$absDelPrep = pg_prepare($conn, 'absDelOne', $absDelSql);
$absDelQry = pg_execute($conn, 'absDelOne', array($id));
};
$resultSql = "UPDATE appointments
SET hour=$1, tutorid=$2,
clientid=$3, purpose=$4,
tutornotshown=$5, clientnotshown=$6
WHERE appid=$7";
$resultPrep = pg_prepare($conn, 'resultSql', $resultSql);
$result = pg_execute($conn, 'resultSql',
array(post('hour'), post("tutor"), post("client"),
post("purpose"), $tutorAbsence, $clientAbsence, $id
)
);
echo json_encode(array("success" => 1));
break;
你檢查了[錯誤](http://php.net/manual/en/function.pg-last-error.php)嗎?什麼是$ 1,$ 2和$ 3? – aynber
我無法從控制檯收到任何錯誤。我在跟蹤錯誤時遇到了問題,我是一個初學者。 $ 1,$ 2,$ 3是準備好的陳述的佔位符。 – Ahmet
查看我發佈的鏈接(點擊單詞錯誤),它會幫助你檢查錯誤。 – aynber