PHP PDO MySQL语法错误

时间:2015-11-20 14:51:56

标签: mysql pdo

你能告诉我MySql语法有什么问题吗?

$sql

使用Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 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 ''submission' (project_id) VALUES ('1')' at line 1 in /app/model/ProjectModel.php on line 54 运行此操作后,我收到此错误:

$sql2

如果我使用$sql运行查询并且没有参数,则执行并插入所需的值。 {"status":"ok"}++ Starting Swift_Transport_EsmtpTransport<br /> &lt;&lt; 220-s206.avahost.net ESMTP Exim 4.86 #2 Fri, 20 Nov 2015 16:42:03 +0200 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. <br /> &gt;&gt; EHLO znaidusvoe.com <br /> &lt;&lt; 250-s206.avahost.net Hello s206.avahost.net [77.120.110.175] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP <br /> &gt;&gt; AUTH LOGIN <br /> &lt;&lt; 334 VXNlcm5hbWU6 <br /> &gt;&gt; c3VwcG9ydEB6bmFpZHVzdm9lLmNvbQ== <br /> &lt;&lt; 334 UGFzc3dvcmQ6 <br /> &gt;&gt; YWRtaW4xcTJ3M2U0cjV0 <br /> &lt;&lt; 235 Authentication succeeded <br /> ++ Swift_Transport_EsmtpTransport started<br /> &gt;&gt; MAIL FROM:&lt;support@znaidusvoe.com&gt; <br /> &lt;&lt; 250 OK <br /> &gt;&gt; RCPT TO:&lt;vladislav.kosko@gmail.com&gt; <br /> &lt;&lt; 250 Accepted <br /> &gt;&gt; DATA <br /> &lt;&lt; 354 Enter message, ending with &quot;.&quot; on a line by itself <br /> &gt;&gt; . <br /> &lt;&lt; 250 OK id=1Zzmt1-002Hws-Op <br /> ++ Stopping Swift_Transport_EsmtpTransport<br /> &gt;&gt; QUIT <br /> &lt;&lt; 221 s206.avahost.net closing connection <br /> ++ Swift_Transport_EsmtpTransport stopped<br /> 查询有什么问题?

1 个答案:

答案 0 :(得分:2)

http://us3.php.net/manual/en/book.pdo.php#69304

  

请注意:

     

赢得了工作:$sth = $dbh->prepare('SELECT name, colour, calories FROM ? WHERE calories < ?');

     

这个工作! $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ?');

     

该参数不能应用于表名!!

正如您在此评论中看到的那样,您无法使用PDO中的参数替换表名或列名。

但您可以使用变量来填充表名或列名,例如

select * from $table where $column_name = "bla bla"