MVC Error

Posted on 2013-10-10
Medium Priority
Last Modified: 2013-10-25
I have a page on my website, that is built on MVC Zend Framework.  I am getting an error message and I am not sure what it means.  The following is the error message.  Can anyone shed any light on what might be the issue?

 Message: 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 ')) ORDER BY `date_entered` DESC, `t_id` DESC' at line 1
Stack trace:
#0 /usr/local/lib/php/Zend/Db/Statement.php(320): Zend_Db_Statement_Pdo->_execute(Array) #1 /usr/local/lib/php/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array) #2 /usr/local/lib/php/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Table_Select), Array) #3 /usr/local/lib/php/Zend/Db/Table/Abstract.php(1516): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Table_Select)) #4 /usr/local/lib/php/Zend/Db/Table/Abstract.php(1332): Zend_Db_Table_Abstract->_fetch(Object(Zend_Db_Table_Select)) #5 /home/mrstaxin/public_html/dev/library/Stax/User/Regional.php(198): Zend_Db_Table_Abstract->fetchAll(Object(Zend_Db_Table_Select)) #6 /home/mrstaxin/public_html/dev/application/controllers/ReportsController.php(46): Stax_User_Regional->getInvoiceReports('', NULL) #7 /usr/local/lib/php/Zend/Controller/Action.php(513): ReportsController->invoicesAction() #8 /usr/local/lib/php/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('invoicesAction') #9 /usr/local/lib/php/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #10 /usr/local/lib/php/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #11 /usr/local/lib/php/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #12 /home/mrstaxin/public_html/dev/index.php(37): Zend_Application->run() #13 {main} 

Open in new window

This is the code that I think it is refering to:
	public function getInvoiceReports($where = null, $order = "date_entered DESC")
		if (is_null($order)) {
			$order = "date_entered DESC";
		$invoices = new Db_Invoices();
		$sel = $invoices->select();
		$sel->where('user_id IN (?)', new Zend_Db_Expr($this->managedUsers(true)))
			->order(array(trim($order), 't_id DESC'));

		if ($where) {

		return $invoices->fetchAll($sel);

Open in new window

Question by:rgranlund
LVL 35

Expert Comment

by:Terry Woods
ID: 39564005
The problem may originate in the value of $where. Can you find out what that is, and post it if you can't see the problem? Perhaps there are non-matching round brackets?

It may also be helpful to output the SQL somehow. I use CodeIgniter rather than Zend so I don't know how to do this, but there should be a way.
LVL 111

Expert Comment

by:Ray Paseur
ID: 39564015
There is a syntax error in the query.  I think you're in the right place tracking it down.  The generated SQL string ends in this.  I'm not sure I can see the error there.

ORDER BY `date_entered` DESC, `t_id` DESC' at line 1

You might want to add var_dump($invoices) at line 15, before the return.  Then you can probably see the entire query string.
LVL 58

Accepted Solution

Gary earned 2000 total points
ID: 39564206
The double bracket in the error would be a bit suspicious

right syntax to use near ')) ORDER BY `date_entered

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question