Issues

ZF-5918: connect errors are supressed when dbname is provided

Issue Type: Improvement Created: 2009-03-02T02:04:57.000+0000 Last Updated: 2009-03-15T07:21:54.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Steve Jordan (stevejordan) Assignee: Mickael Perraud (mikaelkael) Tags: - Zend_Db_Adapter_Oracle

Related issues: Attachments:

Description

It seems a bit inconsistent that oci_connect() errors are suppressed in _connect() when dbname is provided in config.ini, but are not supressed when dbname isn't present.

It caused me a bit of head scratching during a recent connection issue.

Comments

Posted by Mickael Perraud (mikaelkael) on 2009-03-03T13:40:40.000+0000

In this case, Zend_Db_Adapter_Abstract will throw an exception with _checkRequiredOptions():

<pre class="highlight">
Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance")

Since SVN5014, this part of code is unused.

Posted by Steve Jordan (stevejordan) on 2009-03-04T06:18:27.000+0000

sorry, I wasn't very clear in the description.

inside the _connect() function there is the following code:

<pre class="highlight">
        if (isset($this->_config['dbname'])) {
            $this->_connection = @oci_connect(
                $this->_config['username'],
                $this->_config['password'],
                $this->_config['dbname']);
        } else {
            $this->_connection = oci_connect(
                $this->_config['username'],
                $this->_config['password']);
        }

at the moment a check is made to see if dbname has been declared somewhere, and if it has oci_connect has it's errors suppressed (@). There is no error suppression when dbname has not been set.

This is an inconsistency, and caused me some issues while trying to diagnose a connection issue (The exception thrown contained no useful information)

I hope this is clearer.

Posted by Mickael Perraud (mikaelkael) on 2009-03-04T11:14:28.000+0000

You were clear, no problem ;).

Based on actual trunk, I think this code is unreachable. So we could replace:

<pre class="highlight">
if (isset($this->_config['dbname'])) {
    $this->_connection = @oci_connect(
        $this->_config['username'],
        $this->_config['password'],
        $this->_config['dbname']);
} else {
    $this->_connection = oci_connect(
        $this->_config['username'],
        $this->_config['password']);
}

by:

<pre class="highlight">
$this->_connection = @oci_connect(
    $this->_config['username'],
    $this->_config['password'],
    $this->_config['dbname']);

Because $this->_config['dbname'] is mandatory, if it misses, then you have an exception thrown by Zend_Db_Adapter_Abstract::_checkRequiredOptions() before entering in Zend_Db_Adapter_Oracle::_connect()

Posted by Steve Jordan (stevejordan) on 2009-03-05T08:44:18.000+0000

I see what your saying. It sounds like a good idea to remove code which will never be run.

But the problem which I was having (with the empty Exception messages) will still occur in your replacement code, because you still have the @ suppressing error messages.

If you look at the next code block in the file:

<pre class="highlight">
// check the connection
if (!$this->_connection) {
            /**
             * @see Zend_Db_Adapter_Oracle_Exception
             */
            require_once 'Zend/Db/Adapter/Oracle/Exception.php';
            throw new Zend_Db_Adapter_Oracle_Exception(oci_error());
        }

Posted by Steve Jordan (stevejordan) on 2009-03-05T08:45:57.000+0000

sorry, I hit "Add" too soon.

the call to oci_error() will never return anything while the oci_connect() errors are suppressed.

So my suggestion is to remove the @ before oci_connect.

Posted by Mickael Perraud (mikaelkael) on 2009-03-06T12:58:13.000+0000

{quote} the call to oci_error() will never return anything while the oci_connect() errors are suppressed. {quote}

For me, it's false, see these examples:

<pre class="highlight">
<?php
oci_connect('user', 'good_password', 'database');
print_r(oci_error());

=> return nothing

<pre class="highlight">
<?php
oci_connect('user', 'bad_password', 'database');
print_r(oci_error());

=>

<pre class="highlight">
<br></br><b>Warning</b>:  oci_connect() [<a href="function.oci-connect">function.oci-connect</a>]: ORA-01017: invalid username/password; logon denied in <b>D:\web\www\test_oracle.php</b> on line <b>2</b><br></br>
Array
(
    [code] => 1017
    [message] => ORA-01017: invalid username/password; logon denied
    [offset] => 0
    [sqltext] => 
)

<pre class="highlight">
<?php
@oci_connect('user', 'bad_password', 'database');
print_r(oci_error());

=>

<pre class="highlight">
Array
(
    [code] => 1017
    [message] => ORA-01017: invalid username/password; logon denied
    [offset] => 0
    [sqltext] => 
)

The goal of @ is simply to suppress the warning but oci_error() is always populated.

No?

Posted by Steve Jordan (stevejordan) on 2009-03-10T04:19:02.000+0000

It looks like I have misunderstood the purpose of @

In which case the exception thrown needs to contain at least the code and message, something like:

<pre class="highlight">
// check the connection
if (!$this->_connection) {
            /**
             * @see Zend_Db_Adapter_Oracle_Exception
             */
            require_once 'Zend/Db/Adapter/Oracle/Exception.php';
            $errorMessageArray = oci_error();
            throw new Zend_Db_Adapter_Oracle_Exception($errorMessageArray[code] . ': ' . $errorMessageArray[message]);
        }

?

Posted by Mickael Perraud (mikaelkael) on 2009-03-11T01:57:25.000+0000

Open Zend/Db/Adapter/Oracle/Exception.php, you will see how this is managed

Posted by Steve Jordan (stevejordan) on 2009-03-11T02:29:59.000+0000

I see. That makes sense now.

So in my case the lack of an error message is down to oci_error not returning one, rather than the framework's processing.

Thanks for pointing me in the right direction.

Posted by Mickael Perraud (mikaelkael) on 2009-03-15T07:21:45.000+0000

The unreachable code was removed with SVN 14324 to close this issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts