简体   繁体   English

ZF2中的SQL查询语法错误

[英]SQL query syntax error in ZF2

I'm using zend framework 2 in my application. 我在我的应用程序中使用zend framework 2。 I want to simply execute this query... 我只想执行此查询...

$sql = "INSERT INTO tbl_group(group_name, group_order, version_id_fk, group_code)
                            SELECT group_name, group_order, {$newVersionId}, $this->getServiceLocator()->get('commonService')->randomMD5() FROM tbl_group
                            WHERE version_id_fk = {$versionArray['version_id_pk']}";

But I'm getting this error: 但我收到此错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near ')->get('commonService')->randomMD5() FROM tbl_group WHERE version_id_fk ' at line 2 检查与您的MySQL服务器版本相对应的手册,以在第2行的')-> get('commonService')-> randomMD5()FROM tbl_group WHERE version_id_fk'附近使用正确的语法

Can anyone suggest me how to fix this? 谁能建议我如何解决此问题?

Thank you! 谢谢!

period (.) is the concatenation operator in PHP, you are writing SQL. 句点(。)是PHP中的串联运算符,您正在编写SQL。

It should be CURRENT_TIMESTAMP + RAND() 它应该是CURRENT_TIMESTAMP + RAND()

Not select CURRENT_TIMESTAMP . RAND() 不选择CURRENT_TIMESTAMP . RAND() CURRENT_TIMESTAMP . RAND()

There's multiple errors but the one the error message is referring to is due to missing parentheses around your service locator call. 存在多个错误,但错误消息所引用的一个错误是由于服务定位器调用周围缺少括号引起的。

It's trying to execute your php code as sql. 它正在尝试将您的PHP代码执行为sql。

{$this->getService... } {$ this-> getService ...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM