Doctrine_Connection_Exception : PDO Connection Error: SQLSTATE[] (solved!)

October 12, 2009 by Reboot · 5 Comments 

Fatal error: Uncaught exception ‘Doctrine_Connection_Exception’ with message ‘PDO Connection Error: SQLSTATE[]: pdo_oci_handle_factory: OCI_INVALID_HANDLE (/patched-php-src-5.2.10/php-5.2.10/ext/pdo_oci/oci_driver.c:579)’

It’s driving me mad, unable to solve this one, read several assumed “fixes” to this problem but without success.

It’s open for discussion, if you might know a working solution to this issue, please comment!!!

Note: the problem is not a 100% fail but a random occurence, unable to spot the “random” cause, maybe memory leak? connection pool fail?

It is however is risky to use Doctrine for Oracle because the Oracle PHP PDO implementation is experimental and Doctrine seems to require PDO (it however does not!!):

Oracle Functions (PDO_OCI)
http://php.morva.net/manual/en/ref.pdo-oci.php

Thus I would highly advise to NOT use Doctrine with Oracle PDO in professional environments (which requires the PHP PDO extension to be enabled and the driver name to be “oci”).

Note: the Zend_DB (non-PDO) implemetation has no issues, which seems weird, they both use the same internals and environment settings.

Remark: I like Doctrine, it’s extremely handy to create a database independent schema and good for the stable PDO implementations (like MySQL) and is more mature and feature rich than Zend_DB at the moment (my collegue snapped at me that I somehow disapproved Doctrine in general ^_^, which is not the case).

Further reseach showed:

About the Doctrine and PHP PDO:

In Doctrine_Connection on line 472 (Connection.php) there seems to be a strong preference to using the PDO drivers if available:

[line 472]
if (extension_loaded(‘pdo’)) {
if (in_array($e[0], self::getAvailableDrivers())) {

Which also means if the PDO extension is NOT loaded it falls back to it’s “normal” Oracle adapter, which is not experimental, see line 486 of the same file:

[line 486]
if ( ! $found) {
$class = ‘Doctrine_Adapter_’ . ucwords($e[0]);

This said, because the PDO for Oracle is experimental, disabling this PDO extension on the server will result into the use of the stable oci library. There is another option!!

Option 2:

Use “oracle” as a driver name instead of “oci”, they seems to point to the same Doctrine adapter in the Doctrine_Manager class (Manager.php):

[line 263]
‘oci’      => ‘Doctrine_Connection_Oracle’,
‘oci8′     => ‘Doctrine_Connection_Oracle’,
‘oracle’   => ‘Doctrine_Connection_Oracle’,

but only the ‘oci’ one is recognized as being a PDO adapter!!

see also: http://trac.doctrine-project.org/ticket/631

About Reboot
Software Engineer - http://www.linkedin.com/in/orlissenberg

Comments

5 Responses to “Doctrine_Connection_Exception : PDO Connection Error: SQLSTATE[] (solved!)”
  1. Nils says:

    hi,

    so do you have a working solution?
    I am using the symfony frameworking with doctrine and i am getting the same error.
    Using “oracle” instead of “oci” in the connection string is not working.

    There is not very much about that on google. ;-)

  2. Reboot says:

    I don’t know yet, had the day off because it’s my son’s birthday, asked a colleague of mine to check it but he did not get around to it *sighs*. I’m pretty anxious to know if it works though. Cross your fingers. If your try failed, I’m afraid my change to the normal Oracle driver will fail too. Thus using the PDO or normal Oracle driver doesn’t matter …

    At least it shouldn’t report the “PDO Connection Error” part because we’re not using PDO?!?!

  3. Reboot says:

    First try seems successful, although it’s not stress tested yet. We had to change a Doctrine file though, parts of the connection settings were not passed properly. We now have a hard-coded fix in place:

    in the class Doctrine_Adapter_Oracle (file: Oracle.php) line 105 we added
    $this->config['dbname'] = ‘(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host.nl)(PORT=1521)))(CONNECT_DATA=(SID=sid)))’;
    $this->config['charset'] = ‘AL32UTF8′;

    Although the fix is not definitive yet (hard to reproduce the issue because of it’s randomness), it did solve another issue we had (thus Oracle PDO == Experimental == Trouble?).

  4. Reboot says:

    Under (severe) stress, we now sometimes get an “ORA-12519: TNS:no appropriate service handler found” which is a different connection error type but one which can probably be solved easier. Hence the issue in the post is solved, don’t use PDO-Oracle and fix Doctrine!!

    ORA-12519: TNS:no appropriate service handler found tips
    http://www.dba-oracle.com/sf_ora_12519_tns_no_appropriate_service_handler_found.htm

  5. Nils says:

    Thanks for the further information, I hope that I can work on this problem on friday.
    I will try out your workarounds and then get back to you with hopefully positive feedback ;-)

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!