这是我的查询:
SELECT qa.id,
qa.subject,
qa.category cat,
qa.keywords tags,
qa.body_html,
qa.amount,
qa.author_id author,
qa.visibility,
qa.date_time,
COALESCE(u.reputation, 'N') reputation,
COALESCE(CONCAT(u.user_fname, ' ', u.user_lname), 'ناشناس') name,
COALESCE(u.avatar, 'anonymous.png') avatar,
(SELECT COALESCE(sum(vv.value),0)
FROM votes vv
WHERE qa.id = vv.post_id
AND 15 = vv.table_code) AS total_votes,
(SELECT COALESCE(sum(vt.total_viewed),0)
FROM viewed_total vt
WHERE qa.id = vt.post_id
AND 15 = vt.table_code
LIMIT 1) AS total_viewed
FROM qanda qa
INNER JOIN qanda_tags qt ON qt.qanda_id = qa.id
INNER JOIN tags ON tags.id = qt.tag_id
LEFT JOIN users u ON qa.author_id = u.id
AND qa.visibility = 1
WHERE qa.type = 0 tags.name = :t
ORDER BY qa.date_time DESC
LIMIT :j,
11;
并抛出此错误:
致命错误:未捕获的PDOException:SQLSTATE [42000]:语法错误或
访问冲突:1064您的SQL语法错误;检查
相应于您的MariaDB服务器版本的手册
'tags.name =?附近使用的语法ORDER BY qa.date_time desc LIMIT
?,11'在C:\ xampp \ htdocs \ myweb \ others \ questions.php:136中的第18行
堆栈跟踪:#0 C:\ xampp \ htdocs \ myweb \ others \ questions.php(136):
PDO-> prepare('SELECT qa.id,q ...')#1
C:\ xampp \ htdocs \ myweb \ others \ questions.php(293):
问题->索引('tags.name =:t1','\ tINNER JOIN qan ...')#2
C:\ xampp \ htdocs \ myweb \ application \ other.php(21):问题->标记为()
#3 C:\ xampp \ htdocs \ myweb \ index.php(149):require_once('C:\ xampp \ htdocs ...')#4 {main}被抛出
第136行的C:\ xampp \ htdocs \ myweb \ others \ questions.php
我真的不知道出什么问题了。错误消息说它在
tags.name = ?
附近,但这对我来说是完全正确的。有人有什么问题吗?
最佳答案
更换
WHERE qa.type = 0 tags.name = :t
与
WHERE qa.type = 0 AND tags.name = :t
关于mysql - 语法错误或访问冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44828923/