Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get more info on this PDO MySql error with Zend

Tags:

php

mysql

zend-db

In my PHP script I run an update statement as follows:

$this->_db->update('names', $data, $this->_db->quoteInto('id = ?', $obj->id));

The db handle is a Zend_Db_Adapter_Abstract instance (of the PDO MySql variety).

The problem is that the update is failing and I can't seem to get more info on the error.

The error occurs within a try/catch block. When I catch the error, I run:

$db->getProfiler()->getLastQueryProfile();

And the output is:

2012-11-14T22:20:02+11:00 INFO (6): Zend_Db_Profiler_Query Object
(
    [_query:protected] => begin
    [_queryType:protected] => 64
    [_startedMicrotime:protected] => 1352892002.6064
    [_endedMicrotime:protected] => 1352892002.6066
    [_boundParams:protected] => Array
        (
        )

I know it says no parameters are bound, but I really don't think that's the case. I think that somehow 'last query' is not what I think it is.

Secondly, when I catch the error I also run:

$db->getConnection()->errorInfo();

And the output is:

2012-11-14T22:20:02+11:00 INFO (6): Array
(
    [0] => 00000
    [1] => 
    [2] => 
)

Obviously this is not very helpful.

Any ideas? How can I get more info on the error?

Thanks!

like image 834
DatsunBing Avatar asked Nov 13 '22 17:11

DatsunBing


1 Answers

You can force PDO to throw exceptions with all the info:

<?php

$this->_db->->getConnection()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


try {
    $this->_db->update('names', $data, $this->_db->quoteInto('id = ?', $obj->id));
}
catch (Exception $ex) {
    print_r($ex);
}
like image 106
Ivan Krechetov Avatar answered Nov 15 '22 13:11

Ivan Krechetov