2016-08-16 80 views
-2

什麼不對這個語法,請:MySQL查詢錯誤的語法

$stmt = $db->query('SELECT id, par, what, title, inde 
        FROM tmatria 
        ORDER BY inde ASC 
        where par = ' . $_SESSION["par"] . ';'); 

錯誤:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where par = 0' at line 1

+2

ORDER BY應該在WHERE子句之後? – user3741598

+1

** RTM ** http://dev.mysql.com/doc/refman/5.7/en/select.html和'WHERE'是一個保留字,它解釋** first **語法錯誤'near'where 'https://dev.mysql.com/doc/refman/5.7/en/keywords.html –

+0

請閱讀SQL教程。子句的順序不靈活,任何教程都應該顯示正確的語法。 – Barmar

回答

0

錯在何處位置

'SELECT id, par, what, title, inde 
FROM tmatria 
where par = '. $_SESSION["par"] . ' ORDER BY inde ASC ;' 
+0

爲什麼downvote沒有動力? – scaisEdge

0

ORDER子句應該來WHERE子句之後

$stmt = $db->query("SELECT id, par, what, title, inde FROM tmatria where par = '$_SESSION[par]' ORDER BY inde ASC");