PDO语句错误#1064

时间:2015-03-07 11:13:37

标签: mysql pdo prepared-statement

我正试图从PDO引用PDO准备并执行,我的查询就像:

$sql = 'SELECT * FROM nav_top1 WHERE id_top = (SELECT top_fr FROM nav_top WHERE top_fr = :rub ORDER BY top1_order ASC';
echo $sql.'<br>';
$query = $connexion->prepare($sql);
$query->bindParam(':rub', $rub, PDO::PARAM_INT);
$query->execute();
$list = $query->fetchAll();

foreach ($list as $rs) {
$top1_fr = $rs['top1_fr'];

echo $top1_fr;

}

但是我收到了错误:

  

[Sat Mar 07 14:08:05 2015] [错误] [客户105.156.126.211]
  PHP警告:PDOStatement :: execute():SQLSTATE [42000]:语法错误或访问冲突:1064
  您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获得在&#39;&#39;附近使用的正确语法。在第9行/home/www/Fashion/fashion.php的第1行,引用...

提前致谢

2 个答案:

答案 0 :(得分:2)

缺少大括号?

top1_order ASC)

答案 1 :(得分:0)

  

$ sql ='SELECT * FROM nav_top1 WHERE id_top =(SELECT top_fr FROM   nav_top WHERE top_fr =:rub ORDER BY top1_order ASC';

你缺少牙箍。

 $sql = 'SELECT * FROM nav_top1 WHERE id_top = (SELECT top_fr FROM
 nav_top WHERE top_fr = :rub ORDER BY top1_order ASC');