Mysql语法作为预准备语句运行时出错

时间:2012-09-22 10:14:42

标签: mysql database stored-procedures pdo

我有这个存储过程,我在其中使用准备好的语句来执行两个查询。这是程序。

SET @uid    = puserid;
SET @rangee = plimit * 50;
SET @post = 'post';

PREPARE STMT FROM 
'
SELECT  notifications.postid,victims.victimid,friends.friendsname,notificationrecievers.status 

FROM friends,victims,notifications,notificationrecievers

WHERE victims.postid=notifications.postid 

AND notificationrecievers.notificationid=notifications.notid

AND notificationrecievers.recieverid=?

AND notifications.type=? 

AND friends.friendsid=victims.victimid

AND notificationrecievers.notificationid <=
(
   SELECT MAX(notid) FROM
   (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
   )a
)
AND notificationrecievers.notificationid >=
(
   SELECT MIN(notid) FROM
   (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
   )b
)
ORDER BY notifications.postid DESC;

UPDATE notificationrecievers 

SET notificationrecievers.status=1 

WHERE notificationrecievers.status=0
AND   notificationrecievers.recieverid=? 

AND

notificationrecievers.notificationid <=
(
     SELECT MAX(notid) FROM
     (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
     )e
)   

AND

notificationrecievers.notificationid >=
(
     SELECT min(notid) FROM
     (
      SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE
      nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC
      LIMIT 50 OFFSET ?
     )g
);

';
EXECUTE STMT USING @uid,@post,@uid,@rangee,@uid,@rangee,@uid,@uid,@rangee,@uid,@rangee;

当我在程序中运行此查询时,它给出了语法错误。但是当我直接使用它来代替?时使用硬编码值而不是它正常工作。为什么会发生这种情况? puseridplimit是我传递给此程序的参数。

这是错误:

Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';

UPDATE 
notificationrecievers 
SET notificationrecievers.st' at line 25

0 个答案:

没有答案