我遇到問題,無法找到答案。下面的語句爲什麼這個MySQL語句會導致語法錯誤?
SELECT (title, content, keywords, descr, sidebar) FROM staticpages WHERE req = 'index'
引發以下錯誤
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1
我插入帶有mysql_real_escape_string字符串「指數」,但我已經驗證,它包含「索引」。數據庫中有一個符合WHERE的條目(即使沒有,也不應該有語法錯誤)。
//編輯:查詢由下面的PHP代碼產生:
if ($res = $db->query("SELECT title, content, keywords, descr, sidebar FROM staticpages WHERE req = '"+$db->real_escape_string($page)+"'")) {
//...
} else {
echo "Error " . $db->errno . ": " . $db->error;
}
$db
包含mysqli的實例,$page
包含字符串"index"
。
我不認爲您發佈的查詢是滿的,該錯誤信息是指在查詢犯規退出0。 – Mihai
@Mihai也有同感。我將更新問題並向您展示生成查詢的PHP代碼。 – fNek
不確定,但+是javascript中的連接運算符,在PHP中是點。 ''。$ db-> real_escape_string($ page)。''' – Mihai