0

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!

1
  • You have '. {RAND()}) in your query. Of course it can't be parsed Commented Feb 22, 2017 at 7:49

2 Answers 2

1

period (.) is the concatenation operator in PHP, you are writing SQL.

It should be CURRENT_TIMESTAMP + RAND()

Not select CURRENT_TIMESTAMP . RAND()

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for reply and your answer is okay but please see my edited question to how to fix this?
When you change your question, answers will go to waste. When other people read question and answers, they don't understand what is problem, what is best solution for that problem. Don't change your questions radically! @anil
0

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... }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.