由mysqli_prepare()創建的準備語句是服務器端準備好的語句。
當你執行這樣一個準備好的語句時,只傳輸語句ID和參數,而不是某些查詢字符串,就像你用實際參數(客戶端,即你的PHP腳本)替換佔位符一樣。
但是你可以看到的結果在MySQL服務器的通用日誌,看到Prepared Statement Logging
編輯:你的情況,因爲desc
是保留關鍵字聲明的準備失敗。
有關關鍵字的列表以及如何使用它們作爲標識符(如果需要的話)看到http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
$q = '
INSERT INTO
`event`
(
`cityid`, `name`, `desc`, `date`,
`expdate`, `mintix`, `maxtix`,
`contactname`, `contactemail`, `contactphone`
)
VALUES
(
?,?,?,?,
?,?,?,
?,?,?
)
';
if (false===($stmt=mysqli_prepare($dblink, $q))) {
/*
in production-code you might not want to reveal
the error string to each and every user
...but for this example and for debugging purposes:
*/
die('mysqli_prepare failed: '.htmlspecialchars(mysqli_error($dblink)));
}
$rc = mysqli_stmt_bind_param(
$stmt,
"issssiisss",
$city,$name,$desc,$date,
$expdate,$mintix,$maxtix,
$contactname,$contactemail,$contactphone
);
if (false===$rc) {
die('mysqli_stmt_bind_param failed: '.htmlspecialchars(mysqli_stmt_error($stmt)));
}
if (false===mysqli_stmt_execute($stmt)) {
die('mysqli_stmt_execute failed: '.htmlspecialchars(mysqli_stmt_error($stmt)));
}
mysqli_stmt_close($stmt);
請告訴我們你的代碼。否則很難幫助你。 – 2010-03-28 00:13:00
除了byronh評論之外,您還應該能夠將查詢語句存儲在變量中,然後{query,echo,save}查詢語句和錯誤代碼。 – bdl 2010-03-28 00:14:33
@bdl我無法找到一種方法將準備好的語句轉換回字符串(我認爲bigmac所要求的是什麼)。 – 2010-03-28 00:15:45