Postgres_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:3k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class Postgres_Db extends BaseObject {
  3.    var $db;
  4.    var $debug;
  5.    var $db_connection_handle;
  6.    var $connection_init;
  7.    Function Postgres_Db( $db_config = '' ) {
  8.       $this->BaseObject( 'Postgres_Db' );
  9.       if ( is_object( $db_config ) ) {
  10.          $this->db      = $db_config;
  11.       } else {
  12.          $this->db      = new DbDefaults();
  13.       }
  14.       $this->debug                  = new Debug();
  15.       $this->debug->prefix          = 'Postgres_Db::MAIN';
  16.       $this->debug->On();
  17.       $this->db_connection_handle   = false;
  18.       $this->connection_init        = false;
  19.       } /* END Postgres_Db() */
  20.    Function BuildConnectString() {
  21.       if ( $this->db->connect_string == '' ) {
  22.          $this->db->Build_PostgresConnectString();
  23.       }
  24.    } /* END BuildConnectionString */
  25.    Function CreateConnection() {
  26.       $this->BuildConnectString();
  27.       $this->debug->On();
  28.       $open_connection = 0;
  29.       /* Open the connection to the database */
  30.       $open_connection = (
  31.          $this->db_connection_handle = pg_pConnect( 
  32.          $this->db->connect_string
  33.          )
  34.       );
  35.       if ( !( $open_connection) ) {
  36.             $this->debug->Message( 
  37.             'Database Invalid Username / Password Combo : ' . "n" .
  38.             'Db Connect string : ' . $this->db->connect_string . "n" 
  39.             );
  40.          return array( false, 'Broken connect string.' );
  41.       } else {
  42.          $this->connection_init = true;
  43. return true;
  44.       }
  45. return array( false, 'Default error catch' );
  46. } /* END CreateConnection() */
  47.    Function Open() { return $this->CreateConnection(); }
  48.    Function DestroyConnection() {
  49.       if ( $this->connection_init == true ) {
  50.          if ( @pg_Close( $this->db_connection_handle ) ) {
  51.             return array( true );
  52.          } else {
  53.             return array( false );
  54.          }
  55.       }
  56.    }
  57.    Function Close() { return $this->DestroyConnection(); }
  58.    Function PrepareSql( $sql_stmt ) {
  59.       $temp = new Postgres_DbDriver();
  60.       //$this->SelectDb();
  61.       $temp->db_connection_handle = $this->db_connection_handle;
  62.       $temp->sql_statement        = $sql_stmt;
  63.       $temp->debug->debug         = $this->debug->debug;
  64.       return $temp;
  65.    }
  66.    Function SelectDb() {
  67.        /* $select_db =
  68.                (
  69.                $db_test = @Postgres_select_db(
  70.                      $this->db->db_name,
  71.                      $this->db_connection_handle )
  72.                );
  73.          return $select_db;
  74.       */
  75.       return 1;
  76.    }
  77.    Function Prepare( $sql_stmt ) { 
  78.       return $this->PrepareSql( $sql_stmt ); 
  79.    }
  80.    Function ListAllTables() {
  81.       /*if ( 
  82.          $result = @Postgres_listtables( 
  83.                            $this->db->db_name,
  84.                            $this->db_connection_handle
  85.          ) ) {
  86.          $my_arr = Array();
  87.          $i = 0;
  88.          while( $i < @Postgres_num_rows( $result ) ) {
  89.           $my_arr[ $i ] = @Postgres_tablename( $result, $i );
  90.           $i++;
  91.          }
  92.          return Array( true, $my_arr );
  93.       } else {
  94.          return Array( false, @Postgres_error() );
  95.       }
  96. */
  97.    }
  98. } /* END Postgres_Db class */
  99. ?>