I'm using zend framework 2 in my application. 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; 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
Can anyone suggest me how to fix this?
Thank you!
period (.) is the concatenation operator in PHP, you are writing SQL.
It should be CURRENT_TIMESTAMP + RAND()
Not select 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.
{$this->getService... }