- <?php
- class Postgres_Db extends BaseObject {
- var $db;
- var $debug;
- var $db_connection_handle;
- var $connection_init;
- Function Postgres_Db( $db_config = '' ) {
- $this->BaseObject( 'Postgres_Db' );
- if ( is_object( $db_config ) ) {
- $this->db = $db_config;
- } else {
- $this->db = new DbDefaults();
- }
- $this->debug = new Debug();
- $this->debug->prefix = 'Postgres_Db::MAIN';
- $this->debug->On();
- $this->db_connection_handle = false;
- $this->connection_init = false;
- } /* END Postgres_Db() */
- Function BuildConnectString() {
- if ( $this->db->connect_string == '' ) {
- $this->db->Build_PostgresConnectString();
- }
- } /* END BuildConnectionString */
- Function CreateConnection() {
- $this->BuildConnectString();
- $this->debug->On();
- $open_connection = 0;
- /* Open the connection to the database */
- $open_connection = (
- $this->db_connection_handle = pg_pConnect(
- $this->db->connect_string
- )
- );
- if ( !( $open_connection) ) {
- $this->debug->Message(
- 'Database Invalid Username / Password Combo : ' . "n" .
- 'Db Connect string : ' . $this->db->connect_string . "n"
- );
- return array( false, 'Broken connect string.' );
- } else {
- $this->connection_init = true;
- return true;
- }
- return array( false, 'Default error catch' );
- } /* END CreateConnection() */
- Function Open() { return $this->CreateConnection(); }
- Function DestroyConnection() {
- if ( $this->connection_init == true ) {
- if ( @pg_Close( $this->db_connection_handle ) ) {
- return array( true );
- } else {
- return array( false );
- }
- }
- }
- Function Close() { return $this->DestroyConnection(); }
- Function PrepareSql( $sql_stmt ) {
- $temp = new Postgres_DbDriver();
- //$this->SelectDb();
- $temp->db_connection_handle = $this->db_connection_handle;
- $temp->sql_statement = $sql_stmt;
- $temp->debug->debug = $this->debug->debug;
- return $temp;
- }
- Function SelectDb() {
- /* $select_db =
- (
- $db_test = @Postgres_select_db(
- $this->db->db_name,
- $this->db_connection_handle )
- );
- return $select_db;
- */
- return 1;
- }
- Function Prepare( $sql_stmt ) {
- return $this->PrepareSql( $sql_stmt );
- }
- Function ListAllTables() {
- /*if (
- $result = @Postgres_listtables(
- $this->db->db_name,
- $this->db_connection_handle
- ) ) {
- $my_arr = Array();
- $i = 0;
- while( $i < @Postgres_num_rows( $result ) ) {
- $my_arr[ $i ] = @Postgres_tablename( $result, $i );
- $i++;
- }
- return Array( true, $my_arr );
- } else {
- return Array( false, @Postgres_error() );
- }
- */
- }
- } /* END Postgres_Db class */
- ?>