It seems very difficult when you are working with Zend Framework and you are getting some error for some SQL query. It’s hard to debug this issue for you sometimes. Then you may need to know what was the query executed by Zend_Db_Table_Abstract that was generating the precious(!) error?. Well, that’s simple like the snipped below.
May be you have a Profile Model that extends Zend_Db_Table_Abstract and you have a getUserByName function.
[sourcecode language=”php”]
class Application_Model_Profile extends Zend_Db_Table_Abstract {
protected $_name = ‘users’;
function getUserByName( $user_name ) {
$row = $this->fetchRow("username = ‘$user_name’");
if (!$row) {
return false;
}
return $row->toArray();
}
}
[/sourcecode]
We will write our function to debug the query like this:
[sourcecode language=”php”]
class Application_Model_Profile extends Zend_Db_Table_Abstract {
protected $_name = ‘users’;
function getUserByName( $user_name ) {
$this->_db->getProfiler()->setEnabled(true); //start the profiler
$row = $this->fetchRow("username = ‘$user_name’");
$query = $this->_db->getProfiler()->getLastQueryProfile()->getQuery(); //get the last executed query
var_dump( $query ); //show the query
$this->_db->getProfiler()->setEnabled(false); //disable the profiler
if (!$row) {
return false;
}
return $row->toArray();
}
}
[/sourcecode]
What we did?
- We enabled the profiler before executing the query
- Then we executed our query
- Stored our raw query in a variable and print it
- Finally disabled the profiler
That might help you to debug the SQL 😀
The Zf seems to change the way to auth the twitter account. All the old html auth is not working any more
Thanks to share this. I am really looking this for so many days.
My pleasure 😛