Location: PHPKode > scripts > DB factory extension > db-factory-extension/db.class.php
<?
if (!defined("DB")) {
   define("DB","1");
   require_once( 'DB.php' );
   
   class mdb{
     var $_db;

     function db_Connect($p){
       $db = $p['type'];
       $dbhost = $p['host'];
       $dbport = $p['port'];
       $dbuser = $p['user'];
       $dbpass = $p['password'];
       $dbname = $p['dbname'];
       $dsn = "$db://$dbuser:$dbpass@$dbhost:$dbport/$dbname";
       
       if ( DB::isError( $this->_db['cnx'] = DB::connect( "{$dsn}" ) ) ) { 
          $this->_db['error']=DB::errorMessage($this->_db['cnx']);
          $this->_db['debug']=$this->_db['cnx']->getDebugInfo();
         return false;
       }else{
         return true;
       }
     }//db_Connect

     
     function db_dbQuery($p,$q){
       $out = false;
       if($this->db_Connect($p)){
         if(DB::isError($result = $this->_db['cnx']->query($q))){
           $this->_db['error']=DB::errorMessage($result);
           $this->_db['debug']=$result->getDebugInfo();
         }else{
           $out = true;
         }
         $this->db_Disconnect();
       }
       
       return $out;
     }//db_dbQuery

     
     function db_dbArray($p,$q){
       $out = false;
       if($this->db_Connect($p)){
         if(DB::isError( $result = $this->_db['cnx']->query($q))) {
           $this->_db['error']=DB::errorMessage($result);
           $this->_db['debug']=$result->getDebugInfo();
         }else{
           while ($row =& $result->fetchRow(DB_FETCHMODE_ASSOC)) {
             $this->_db['data'][]=$row;
           }
           $out = true;
         }
         $this->db_Disconnect();
       }
       return $out;
     }//dbQueryArray
     
     function db_Disconnect(){
         if ( DB::isError($this->_db['cnx']->disconnect()) ) {
            $this->_db['error']=DB::errorMessage($this->_db['cnx']);
            return false;
         }else{
            return true;
         }
     }//db_Disconnect
   
   }//pgdb

   
}//db   
?>
Return current item: DB factory extension