Doctrine_Connection_Exception : PDO Connection Error: SQLSTATE[] (solved!)
October 12, 2009 by Reboot · 6 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!!
Setting the Character Set to UTF8 in Zend_DB for Oracle.
October 6, 2009 by Reboot · Leave a Comment
—– code snippet —–
$options = array(
‘host’ => ‘host.org’ ,
‘username’ => ‘uname’ ,
‘password’ => ‘upass’ ,
‘dbname’ => ‘name/SID’ , // (servicename requires NLS lookup entry!)
‘charset’ => ‘AL32UTF8′
);
$db = Zend_Db::factory(‘Oracle’, $options);
see also:
Thread: ORACLE UTF Chacter with PHP
http://forums.oracle.com/forums/thread.jspa?messageID=1930036
and
—– code snippet from ZendServer\share\ZendFramework\library\Zend\Db\Oracle.php —–
…
$connectionFuncName = ($this->_config['persistent'] == true) ? ‘oci_pconnect’ : ‘oci_connect’;
$this->_connection = @$connectionFuncName(
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname'],
$this->_config['charset']);
// check the connection
…