因此,這裏的代碼塊:PHP - 準備好的語句錯誤,出了什麼問題?
$query = "UPDATE users SET ?=? WHERE ?=?";
$type = "s";
$type .= substr(gettype($valname), 0, 1);
$type .= 'i';
if ($smtp = $this->conn->prepare($query))
{
$smtp->bind_param($type, $colname, $valname, 'id', 40);
$smtp->execute();
$smtp->close();
}else
{
return $this->conn->error;
}
出於某種原因拒不綁定的參數,它給了我這個錯誤: 您在您的SQL語法錯誤;檢查與你的MySQL服務器版本相對應的手冊,在'?=?'附近使用正確的語法。哪裏?=?'在1號線
如果我加上'圍繞questionmarks我得到這個錯誤,而不是:
未知列反引號(')或singlequotes()‘?’ in'where clause'
任何想法出了什麼問題?我一直坐在這裏玩了幾個小時,上帝讓人沮喪!
非常感謝!
啊,好吧。您可能是正確的,但我現在有另一個錯誤:致命錯誤:不能通過引用blablbla ....參數3,現在的查詢看起來像這樣:「UPDATE users SET $ colname =?WHERE id =?」,看起來好?我也從bind_param函數中刪除了列名:($ type,$ valname,40)。 – qwerty 2010-09-02 16:04:22
我忘了說我也修復了$ type參數。仍然沒有工作... – qwerty 2010-09-02 16:09:40
知道了!我將ID移動到一個單獨的字符串,然後將函數中的字符串鏈接起來。似乎工作! :) – qwerty 2010-09-02 16:12:04