129 $Config = explode(
"#" , $ConfigRow );
131 $this->Username =
$Config[ 1 ];
132 $this->Password =
$Config[ 2 ];
133 $this->Database =
$Config[ 3 ];
134 $this->TablenamePrefix =
$Config[ 4 ];
136 $this->Connection = @pg_pconnect(
137 'host='.$this->Host.
' user='.$this->Username.
' password='.$this->Password.
' dbname='.$this->Database
140 catch( Exception $e )
168 if( $this->Connection ===
false || $ForceReconnect ===
true )
170 if( $this->Connection !==
false )
172 pg_close( $this->Connection );
174 $DBConfigSet =
get_package(
'database::db_config_set' ,
'last' , __FILE__ );
175 $DBConfigSet->load_config( dirname( __FILE__ ).
'/conf/cf_postgre_database' );
176 $this->Connection = $DBConfigSet->connect( $this );
177 if( pg_last_error() !==
false )
181 'An error occured while setting connection to the database '.pg_last_error()
186 return( $this->Connection );
188 catch( Exception $e )
218 $Start = microtime(
true );
219 $Query = str_replace(
'umx_' , $this->TablenamePrefix , $Query );
223 throw(
new Exception(
'An error occured while query execution '.
$Connection->error ) );
225 $End = microtime(
true );
227 if( $this->DBLogging )
231 'action_name , time , info' ,
"'".self::$QueryName.
"' , ".( $End - $Start ).
" , '".
232 htmlspecialchars( $Query , ENT_QUOTES ).
"'"
238 catch( Exception $e )
266 self::$QueryMode = $theQueryMode;
268 catch( Exception $e )
304 function select( $What , $Tables , $Condition =
'1 = 1' )
308 $Result = $this->
query(
"SELECT $What FROM $Tables WHERE $Condition" );
312 catch( Exception $e )
344 $RetValues = array();
346 for( $i = 0; $i < $Result->num_rows ; $i++ )
350 $RetValues [] = $Result->fetch_array( MYSQLI_ASSOC );
354 $RetValues [] = $Result->fetch_object();
360 return( $RetValues );
362 catch( Exception $e )
394 function insert( $Table , $Fields , $Values )
398 $this->
query(
"INSERT INTO $Table ( $Fields ) VALUES ( $Values )" );
400 catch( Exception $e )
428 function delete( $Table , $Condition =
'1 = 1' )
432 $this->
query(
"DELETE FROM $Table WHERE $Condition" );
434 catch( Exception $e )
470 function update( $Table , $Fields , $Values , $Condition =
'1 = 1' )
476 for( $i = 0 ; $i < count( $Fields ) - 1 ; $i++ )
478 $SubQuery .= $Fields[ $i ].
' = '.$Values[ $i ].
' , ';
480 $SubQuery .= $Fields[ count( $Fields ) - 1 ].
' = '.$Values[ count( $Fields ) - 1 ];
482 $this->
query(
"UPDATE $Table SET $SubQuery WHERE $Condition" );
484 catch( Exception $e )
512 function create( $Table , $FirstIndexField =
'id' )
517 "CREATE TABLE `$Table` ( `$FirstIndexField` INTEGER UNSIGNED NOT NULL DEFAULT NULL ".
518 "AUTO_INCREMENT , PRIMARY KEY ( `$FirstIndexField` ) )"
521 catch( Exception $e )
549 $this->
query(
"DROP TABLE $Table" );
551 catch( Exception $e )
587 function add_column( $Table , $ColumnName , $Type , $Mode =
'NOT NULL AFTER `id`' )
591 $this->
query(
"ALTER TABLE `$Table` ADD COLUMN `$ColumnName` $Type $Mode" );
593 catch( Exception $e )
625 $this->
query(
"ALTER TABLE `$Table` DROP COLUMN `$ColumnName`" );
627 catch( Exception $e )
655 function lock( $Tables , $Modes )
659 throw(
new Exception(
"Table locking unavailable" ) );
661 catch( Exception $e )
685 throw(
new Exception(
"Table locking unavailable" ) );
687 catch( Exception $e )
715 $this->
query(
'SAVEPOINT '.$Savepoint );
717 catch( Exception $e )
745 $this->
query(
'ROLLBACK TO SAVEPOINT '.$Savepoint );
747 catch( Exception $e )
771 $this->
query(
'START TRANSACTION' );
773 catch( Exception $e )
797 $this->
query(
'COMMIT' );
799 catch( Exception $e )