Hello.

I received some code that has a section in which the variable $DB is established.

$DB =& new DB($db_username, $db_password, $db_dsn, false);

It does this by calling a function named DB, which is shown here below.

    /**
    * Constructor
    *
    * will set $DB->error and return false if login fails
    *
    * @param string $user
    * @param string $password
    * @param string $db_name
    * @param bool $persistent Should this be a persistent db connection ?
    * @param integer $int_mode
    * @return bool
    **/
    function DB ( $user, $password, $db_name, $persistent=TRUE, $int_mode=OCI_COMMIT_ON_SUCCESS )
    {
        $this->_valid_connection = false;
        $this->query_count = 0;
        $this->debug = false;
        $this->statement_handle = '';
        $this->int_mode = $int_mode;

        if ( $persistent )
        {
            $this->db_handle = OCIPlogon($user,$password,$db_name, 'AMERICAN_AMERICA.AL32UTF8');
        } else {
            $this->db_handle = OCIlogon($user,$password,$db_name, 'AMERICAN_AMERICA.AL32UTF8');
        }

        if ( !$this->db_handle )
        {
            $this->throwError(OCIerror());
            Message::addAlert('Error: Unable to connect to Database');
            return false;
        }
        return true;
    }

    /**
    * Destructor
    *
    * this will only get called if you call it ( limitation of the current version of PHP )
    * but don't worry... PHP cleans up after us anyway.
    *
    * @return void
    **/
    function _DB ()
    {
        OCILogOff($this->db_handle);
    }

But I'm having trouble understanding exactly what it does and when run all I get is a blank page. Can somebody please explain why the DB function is not working correctly?

Thanks.

Hi,

This class is a DB connector class.. you still have to provide the query for it to work..

I just want to let you know that OCIPlogon alias has been deprecated. Use oci_pconnect instead.

Here is an example of an oracle connector with persistent connection and with query included .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.