我有寫有PDO的SQL查詢,我得到這個錯誤:PDO SQL查詢選擇
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
我的代碼是:
$dbh = new PDO("mysql:host=$hostname;charset=utf8;dbname=$database", $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT
'".$perfix."'_k2_items.id AS `ItemId`,
'".$perfix."'_k2_items.title AS `Title`,
'".$perfix."'_k2_items.alias AS `Alias`,
'".$perfix."'_k2_items.catid AS `CatId`,
LEFT('".$perfix."'_k2_items.introtext,1000) AS `Fulltext`,
'".$perfix."'_k2_items.created AS `created`,
'".$perfix."'_k2_categories.name AS `CatName`
FROM '".$perfix."'_k2_items
INNER JOIN '".$perfix."'_k2_categories
ON '".$perfix."'_k2_items.catid = '".$perfix."'_k2_categories.id
WHERE '".$perfix."'_k2_items.featured = '1' ";
的錯誤是前綴。我認爲我犯了一個sytax錯誤。
你能幫我嗎?
謝謝
'$ perfix'的價值是什麼?你爲什麼用引號(')括起來? – vhu
Pefix是一種刺痛。是sql表的perfix。這是一個:$ perfix =「table1」;引號(')是因爲我在代碼的開始處使用了雙引號。 –
@JamesFourikis我已經更新了我的答案。 – Hassaan