ultimix
postgre_database_1_0_0 Class Reference

Public Member Functions

 connect ($ConfigRow)
 get_connection ($ForceReconnect=false)
 query ($Query)
 query_as ($theQueryMode)
 select ($What, $Tables, $Condition= '1=1')
 fetch_results ($Result)
 insert ($Table, $Fields, $Values)
 delete ($Table, $Condition= '1=1')
 update ($Table, $Fields, $Values, $Condition= '1=1')
 create ($Table, $FirstIndexField= 'id')
 drop ($Table)
 add_column ($Table, $ColumnName, $Type, $Mode= 'NOT NULL AFTER`id`')
 drop_column ($Table, $ColumnName)
 lock ($Tables, $Modes)
 unlock ()
 savepoint ($Savepoint)
 rollback ($Savepoint)
 transaction ()
 commit ()

Data Fields

 $Connection = false
 $Config = false
 $Host
 $Username
 $Password
 $Database
 $TablenamePrefix
 $DBLogging

Static Public Attributes

static $LockedTables = false
static $LockModes = false
static $QueryMode = DB_ASSOC_ARRAY

Detailed Description

Class providees routine for database manipulation.

Author
Dodonov A.A.

Definition at line 26 of file postgre_database.php.

Member Function Documentation

add_column (   $Table,
  $ColumnName,
  $Type,
  $Mode = 'NOT NULL AFTER `id`' 
)

Function inserts column in table.

Parameters
$Table- таблица, в которую добавляется столбец.
$ColumnName- имя столбца.
$Type- Тип столбца.
$Mode- Режим добавления столбца.
Exceptions
Exception- кидается исключение этого типа с описанием ошибки.
Author
Додонов А.А.

Definition at line 587 of file postgre_database.php.

{
try
{
$this->query( "ALTER TABLE `$Table` ADD COLUMN `$ColumnName` $Type $Mode" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
commit ( )

Function commits transaction.

Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 793 of file postgre_database.php.

{
try
{
$this->query( 'COMMIT' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
connect (   $ConfigRow)

Function connects to database.

Parameters
$ConfigRow- String from the config.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 125 of file postgre_database.php.

{
try
{
$Config = explode( "#" , $ConfigRow );
$this->Host = $Config[ 0 ];
$this->Username = $Config[ 1 ];
$this->Password = $Config[ 2 ];
$this->Database = $Config[ 3 ];
$this->TablenamePrefix = $Config[ 4 ];
$this->Connection = @pg_pconnect(
'host='.$this->Host.' user='.$this->Username.' password='.$this->Password.' dbname='.$this->Database
);
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
create (   $Table,
  $FirstIndexField = 'id' 
)

Executes delete query.

Parameters
$Table- Created table.
$FirstIndexField- name of index field. Field will be created automatically.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 512 of file postgre_database.php.

{
try
{
$this->query(
"CREATE TABLE `$Table` ( `$FirstIndexField` INTEGER UNSIGNED NOT NULL DEFAULT NULL ".
"AUTO_INCREMENT , PRIMARY KEY ( `$FirstIndexField` ) )"
);
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
delete (   $Table,
  $Condition = '1 = 1' 
)

Executes delete query.

Parameters
$Table- Record (or records) will be deleted from this table.
$Condition- Record selection condition.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 428 of file postgre_database.php.

{
try
{
$this->query( "DELETE FROM $Table WHERE $Condition" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
drop (   $Table)

Executes delete table query.

Parameters
$Table- Deleted table.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 545 of file postgre_database.php.

{
try
{
$this->query( "DROP TABLE $Table" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
drop_column (   $Table,
  $ColumnName 
)

Function deletes column from table.

Parameters
$Table- Name of the editig table (column will be deleted).
$ColumnName- Name of the deleting column.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 621 of file postgre_database.php.

{
try
{
$this->query( "ALTER TABLE `$Table` DROP COLUMN `$ColumnName`" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
fetch_results (   $Result)

Function fetches results of the query.

Parameters
$Result- query result object.
Returns
Array of selected records.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 340 of file postgre_database.php.

{
try
{
$RetValues = array();
for( $i = 0; $i < $Result->num_rows ; $i++ )
{
if( self::$QueryMode == DB_ASSOC_ARRAY )
{
$RetValues [] = $Result->fetch_array( MYSQLI_ASSOC );
}
elseif( self::$QueryMode == DB_OBJECT )
{
$RetValues [] = $Result->fetch_object();
}
}
$Result->close();
return( $RetValues );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_connection (   $ForceReconnect = false)

Function returns database connection.

Parameters
$ForceReconnect- Force reconnect to database.
Returns
mysqli object.
Author
Dodonov A.A.

Definition at line 164 of file postgre_database.php.

{
try
{
if( $this->Connection === false || $ForceReconnect ===true )
{
if( $this->Connection !== false )
{
pg_close( $this->Connection );
}
$DBConfigSet = get_package( 'database::db_config_set' , 'last' , __FILE__ );
$DBConfigSet->load_config( dirname( __FILE__ ).'/conf/cf_postgre_database' );
$this->Connection = $DBConfigSet->connect( $this );
if( pg_last_error() !== false )
{
throw(
new Exception(
'An error occured while setting connection to the database '.pg_last_error()
)
);
}
}
return( $this->Connection );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
insert (   $Table,
  $Fields,
  $Values 
)

Executes insert query.

Parameters
$Table- New record will be inserted in this table.
$Fields- list of fields wich will be filled while record insertion.
$Values- field values.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 394 of file postgre_database.php.

{
try
{
$this->query( "INSERT INTO $Table ( $Fields ) VALUES ( $Values )" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
lock (   $Tables,
  $Modes 
)

Function blocks tables.

Parameters
$Tables- Tables to block.
$Modes- Blocking modes.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 655 of file postgre_database.php.

{
try
{
throw( new Exception( "Table locking unavailable" ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
query (   $Query)

Function executes query.

Parameters
$Query- query string.
Returns
Query result.
Author
Dodonov A.A.

Definition at line 212 of file postgre_database.php.

{
try
{
$Start = microtime( true );
$Query = str_replace( 'umx_' , $this->TablenamePrefix , $Query );
$Result = pg_query( $Connection , $Query );
if( $Connection->errno !== 0 )
{
throw( new Exception( 'An error occured while query execution '.$Connection->error ) );
}
$End = microtime( true );
if( $this->DBLogging )
{
$this->insert(
'umx_actions' ,
'action_name , time , info' , "'".self::$QueryName."' , ".( $End - $Start )." , '".
htmlspecialchars( $Query , ENT_QUOTES )."'"
);
}
return( $Result );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
query_as (   $theQueryMode)

Mode of extracting data from table.

Parameters
$theQueryMode- either DB_ASSOC_ARRAY or DB_OBJECT.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 262 of file postgre_database.php.

{
try
{
self::$QueryMode = $theQueryMode;
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
rollback (   $Savepoint)

Function rollbacks transaction to savepoint.

Parameters
$Savepoint- savepoint.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 741 of file postgre_database.php.

{
try
{
$this->query( 'ROLLBACK TO SAVEPOINT '.$Savepoint );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
savepoint (   $Savepoint)

Function sets savepoint.

Parameters
$Savepoint- savepoint.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 711 of file postgre_database.php.

{
try
{
$this->query( 'SAVEPOINT '.$Savepoint );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
select (   $What,
  $Tables,
  $Condition = '1 = 1' 
)

Function executes select query.

Parameters
$What- List of selecting fields.
$Tables- List of tables to select data.
$Condition- Condition for records filtering.
Returns
Array of selected records.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 304 of file postgre_database.php.

{
try
{
$Result = $this->query( "SELECT $What FROM $Tables WHERE $Condition" );
return( $this->fetch_results( $Result ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
transaction ( )

Function starts new transaction.

Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 767 of file postgre_database.php.

{
try
{
$this->query( 'START TRANSACTION' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
unlock ( )

Function releases all locks for all tables.

Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 681 of file postgre_database.php.

{
try
{
throw( new Exception( "Table locking unavailable" ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
update (   $Table,
  $Fields,
  $Values,
  $Condition = '1 = 1' 
)

Executes update query.

Parameters
$Table- Record (or records) will be updated in this table.
$Fields- list of fields wich will be filled while record update.
$Values- field values.
$Condition- Record selection condition.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 470 of file postgre_database.php.

{
try
{
$SubQuery = '';
for( $i = 0 ; $i < count( $Fields ) - 1 ; $i++ )
{
$SubQuery .= $Fields[ $i ].' = '.$Values[ $i ].' , ';
}
$SubQuery .= $Fields[ count( $Fields ) - 1 ].' = '.$Values[ count( $Fields ) - 1 ];
$this->query( "UPDATE $Table SET $SubQuery WHERE $Condition" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$Config = false

Config.

Author
Dodonov A.A.

Definition at line 88 of file postgre_database.php.

$Connection = false

Connection object.

Author
Dodonov A.A.

Definition at line 38 of file postgre_database.php.

$Database

Definition at line 103 of file postgre_database.php.

$DBLogging

Definition at line 105 of file postgre_database.php.

$Host

DB connection parameters.

Author
Dodonov A.A.

Definition at line 100 of file postgre_database.php.

$LockedTables = false
static

List pf blocked tables.

Author
Dodonov A.A.

Definition at line 50 of file postgre_database.php.

$LockModes = false
static

Lock modes.

Author
Dodonov A.A.

Definition at line 62 of file postgre_database.php.

$Password

Definition at line 102 of file postgre_database.php.

$QueryMode = DB_ASSOC_ARRAY
static

Data querying mode. Either DB_ASSOC_ARRAY (record is reprecented as associative array) or DB_OBJECT (record is represented as an object).

Author
Dodonov A.A.

Definition at line 76 of file postgre_database.php.

$TablenamePrefix

Definition at line 104 of file postgre_database.php.

$Username

Definition at line 101 of file postgre_database.php.


The documentation for this class was generated from the following file: