irm-1.6-b3/MDB/mysql.php
/**
     * Connect to the database
     *
     * @return TRUE on success, MDB_Error on failure
     **/
Connect to the database
@return TRUE on success, MDB_Error on failure
Connect to the database @return TRUE on success MDB_Error on failure
function connect()
    {
        $port = (isset($this->port) ? $this->port : '');
        if($this->connection != 0) {
            if (!strcmp($this->connected_host, $this->host)
                && !strcmp($this->connected_user, $this->user)
                && !strcmp($this->connected_password, $this->password)
                && !strcmp($this->connected_port, $port)
                && $this->opened_persistent == $this->options['persistent'])
            {
                return(MDB_OK);
            }
            @mysql_close($this->connection);
            $this->connection = 0;
            $this->affected_rows = -1;
        }
        if(!PEAR::loadExtension($this->phptype)) {
            return(PEAR::raiseError(NULL, MDB_ERROR_NOT_FOUND,
                NULL, NULL, 'extension '.$this->phptype.' is not compiled into PHP',
                'MDB_Error', TRUE));
        }
        $UseTransactions = $this->getOption('UseTransactions');
        if(!MDB::isError($UseTransactions) && $UseTransactions) {
            $this->supported['Transactions'] = 1;
            $this->default_table_type = 'BDB';
        } else {
            $this->supported['Transactions'] = 0;
            $this->default_table_type = '';
        }
        $DefaultTableType = $this->getOption('DefaultTableType');
        if(!MDB::isError($DefaultTableType) && $DefaultTableType) {
            switch($this->default_table_type = strtoupper($DefaultTableType)) {
                case 'BERKELEYDB':
                    $this->default_table_type = 'BDB';
                case 'BDB':
                case 'INNODB':
                case 'GEMINI':
                    break;
                case 'HEAP':
                case 'ISAM':
                case 'MERGE':
                case 'MRG_MYISAM':
                case 'MYISAM':
                    if(isset($this->supported['Transactions'])) {
                        $this->warnings[] = $DefaultTableType
                            .' is not a transaction-safe default table type';
                    }
                    break;
                default:
                    $this->warnings[] = $DefaultTableType
                        .' is not a supported default table type';
            }
        }
        $this->fixed_float = 30;
        $function = ($this->options['persistent'] ? 'mysql_pconnect' : 'mysql_connect');
        if (!function_exists($function)) {
            return($this->raiseError(MDB_ERROR_UNSUPPORTED));
        }
        @ini_set('track_errors', TRUE);
        $this->connection = @$function(
            $this->host.(!strcmp($port,'') ? '' : ':'.$port),
            $this->user, $this->password);
        @ini_restore('track_errors');
        if ($this->connection <= 0) {
            return($this->raiseError(MDB_ERROR_CONNECT_FAILED, NULL, NULL,
                $php_errormsg));
        }
        if (isset($this->options['fixedfloat'])) {
            $this->fixed_float = $this->options['fixedfloat'];
        } else {
            if (($result = @mysql_query('SELECT VERSION()', $this->connection))) {
                $version = explode('.', @mysql_result($result,0,0));
                $major = intval($version[0]);
                $minor = intval($version[1]);
                $revision = intval($version[2]);
                if ($major > 3 || ($major == 3 && $minor >= 23
                    && ($minor > 23 || $revision >= 6)))
                {
                    $this->fixed_float = 0;
                }
                @mysql_free_result($result);
            }
        }
        if (isset($this->supported['Transactions']) && !$this->auto_commit) {
            if (!@mysql_query('SET AUTOCOMMIT = 0', $this->connection)) {
                @mysql_close($this->connection);
                $this->connection = 0;
                $this->affected_rows = -1;
                return($this->raiseError());
            }
            $this->in_transaction = TRUE;
        }
        $this->connected_host = $this->host;
        $this->connected_user = $this->user;
        $this->connected_password = $this->password;
        $this->connected_port = $port;
        $this->opened_persistent = $this->getoption('persistent');
        return(MDB_OK);
    }
function connect ( ) { $ port = ( isset ( $ this -> port ) ? $ this -> port : '' ) ; if ( $ this -> connection != 0 ) { if ( ! strcmp ( $ this -> connected_host , $ this -> host ) && ! strcmp ( $ this -> connected_user , $ this -> user ) && ! strcmp ( $ this -> connected_password , $ this -> password ) && ! strcmp ( $ this -> connected_port , $ port ) && $ this -> opened_persistent == $ this -> options [ 'persistent' ] ) { return ( MDB_OK ) ; } @ mysql_close ( $ this -> connection ) ; $ this -> connection = 0 ; $ this -> affected_rows = - 1 ; } if ( ! PEAR :: loadExtension ( $ this -> phptype ) ) { return ( PEAR :: raiseError ( NULL , MDB_ERROR_NOT_FOUND , NULL , NULL , 'extension ' . $ this -> phptype . ' is not compiled into PHP' , 'MDB_Error' , TRUE ) ) ; } $ UseTransactions = $ this -> getOption ( 'UseTransactions' ) ; if ( ! MDB :: isError ( $ UseTransactions ) && $ UseTransactions ) { $ this -> supported [ 'Transactions' ] = 1 ; $ this -> default_table_type = 'BDB' ; } else { $ this -> supported [ 'Transactions' ] = 0 ; $ this -> default_table_type = '' ; } $ DefaultTableType = $ this -> getOption ( 'DefaultTableType' ) ; if ( ! MDB :: isError ( $ DefaultTableType ) && $ DefaultTableType ) { switch ( $ this -> default_table_type = strtoupper ( $ DefaultTableType ) ) { case 'BERKELEYDB' : $ this -> default_table_type = 'BDB' ; case 'BDB' : case 'INNODB' : case 'GEMINI' : break ; case 'HEAP' : case 'ISAM' : case 'MERGE' : case 'MRG_MYISAM' : case 'MYISAM' : if ( isset ( $ this -> supported [ 'Transactions' ] ) ) { $ this -> warnings [ ] = $ DefaultTableType . ' is not a transaction-safe default table type' ; } break ; default : $ this -> warnings [ ] = $ DefaultTableType . ' is not a supported default table type' ; } } $ this -> fixed_float = 30 ; $ function = ( $ this -> options [ 'persistent' ] ? 'mysql_pconnect' : 'mysql_connect' ) ; if ( ! function_exists ( $ function ) ) { return ( $ this -> raiseError ( MDB_ERROR_UNSUPPORTED ) ) ; } @ ini_set ( 'track_errors' , TRUE ) ; $ this -> connection = @ $ function ( $ this -> host . ( ! strcmp ( $ port , '' ) ? '' : ':' . $ port ) , $ this -> user , $ this -> password ) ; @ ini_restore ( 'track_errors' ) ; if ( $ this -> connection <= 0 ) { return ( $ this -> raiseError ( MDB_ERROR_CONNECT_FAILED , NULL , NULL , $ php_errormsg ) ) ; } if ( isset ( $ this -> options [ 'fixedfloat' ] ) ) { $ this -> fixed_float = $ this -> options [ 'fixedfloat' ] ; } else { if ( ( $ result = @ mysql_query ( 'SELECT VERSION()' , $ this -> connection ) ) ) { $ version = explode ( '.' , @ mysql_result ( $ result , 0 , 0 ) ) ; $ major = intval ( $ version [ 0 ] ) ; $ minor = intval ( $ version [ 1 ] ) ; $ revision = intval ( $ version [ 2 ] ) ; if ( $ major > 3 || ( $ major == 3 && $ minor >= 23 && ( $ minor > 23 || $ revision >= 6 ) ) ) { $ this -> fixed_float = 0 ; } @ mysql_free_result ( $ result ) ; } } if ( isset ( $ this -> supported [ 'Transactions' ] ) && ! $ this -> auto_commit ) { if ( ! @ mysql_query ( 'SET AUTOCOMMIT = 0' , $ this -> connection ) ) { @ mysql_close ( $ this -> connection ) ; $ this -> connection = 0 ; $ this -> affected_rows = - 1 ; return ( $ this -> raiseError ( ) ) ; } $ this -> in_transaction = TRUE ; } $ this -> connected_host = $ this -> host ; $ this -> connected_user = $ this -> user ; $ this -> connected_password = $ this -> password ; $ this -> connected_port = $ port ; $ this -> opened_persistent = $ this -> getoption ( 'persistent' ) ; return ( MDB_OK ) ; }
Connect to the database
 @return TRUE on success, MDB_Error on failure
Connect to the database @return TRUE on success MDB_Error on failure