语法错误或访问冲突

时间:2017-06-29 15:10:16

标签: mysql sql pdo syntax

这是我的问题:

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 =?附近使用的语法?订购qa.date_time desc LIMIT   ?,11'在C:\ xampp \ htdocs \ myweb \ others \ questions.php:第18行   堆栈跟踪:#0 C:\ xampp \ htdocs \ myweb \ others \ questions.php(136):   PDO->准备(' SELECT qa.id,q ...')#1   C:\ XAMPP \ htdocs中\ MyWeb即可\人\ questions.php(293):   问题>索引(' tags.name =:t1',' \ tINNER加入qan ......')#2   C:\ xampp \ htdocs \ myweb \ application \ other.php(21):questions-> tagged()   #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 = ?,但它对我来说完全正确。

有人问题是什么?

1 个答案:

答案 0 :(得分:2)

替换

WHERE qa.type = 0 tags.name = :t

WHERE qa.type = 0 AND tags.name = :t
相关问题