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) |
| | initial_lock ($Tables, $Modes) |
| | try_lock_table ($Tables, $Modes, $i) |
| | lock ($Tables, $Modes) |
| | unlock () |
| | savepoint ($Savepoint) |
| | rollback ($Savepoint) |
| | transaction () |
| | commit () |
Detailed Description
Class providees routine for database manipulation.
- Author
- Dodonov A.A.
Definition at line 26 of file mysql_database.php.
Member Function Documentation
| add_column |
( |
|
$Table, |
|
|
|
$ColumnName, |
|
|
|
$Type, |
|
|
|
$Mode = 'NOT NULL AFTER `id`' |
|
) |
| |
Function inserts column in table.
- Parameters
-
| $Table | - Name of the editig table (new column will be inserted). |
| $ColumnName | - Name of the inserting column. |
| $Type | - Type of the column. |
| $Mode | - Column insertion mode. |
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 572 of file mysql_database.php.
{
try
{
$this->
query(
"ALTER TABLE `$Table` ADD COLUMN `$ColumnName` $Type $Mode" );
}
catch( Exception $e )
{
}
}
Function commits transaction.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 894 of file mysql_database.php.
{
try
{
$this->
query(
'COMMIT' );
}
catch( Exception $e )
{
}
}
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 112 of file mysql_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 = @new mysqli( $this->Host , $this->Username , $this->Password , $this->Database );
}
catch( Exception $e )
{
}
}
| create |
( |
|
$Table, |
|
|
|
$FirstIndexField = 'id' |
|
) |
| |
Executes delete query.
- Parameters
-
| $Table | - Table to create. |
| $FirstIndexField | - Index field name. |
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Додонов А.А.
Definition at line 497 of file mysql_database.php.
{
try
{
"CREATE TABLE `$Table` ( `$FirstIndexField` INTEGER UNSIGNED NOT NULL DEFAULT NULL ".
"AUTO_INCREMENT , PRIMARY KEY ( `$FirstIndexField` ) )"
);
}
catch( Exception $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 413 of file mysql_database.php.
{
try
{
$this->
query(
"DELETE FROM $Table WHERE $Condition" );
}
catch( Exception $e )
{
}
}
Executes delete table query.
- Parameters
-
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 530 of file mysql_database.php.
{
try
{
$this->
query(
"DROP TABLE $Table" );
}
catch( Exception $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 606 of file mysql_database.php.
{
try
{
$this->
query(
"ALTER TABLE `$Table` DROP COLUMN `$ColumnName`" );
}
catch( Exception $e )
{
}
}
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 321 of file mysql_database.php.
{
try
{
$RetValues = array();
for( $i = 0; $i < $Result->num_rows ; $i++ )
{
{
$RetValues [] = $Result->fetch_array( MYSQLI_ASSOC );
}
{
$RetValues [] = $Result->fetch_array( MYSQLI_NUM );
}
{
$RetValues [] = $Result->fetch_object();
}
}
$Result->close();
return( $RetValues );
}
catch( Exception $e )
{
}
}
| get_connection |
( |
|
$ForceReconnect = false | ) |
|
Function returns database connection.
- Parameters
-
| $ForceReconnect | - Force reconnect to database. |
- Returns
- mysqli object.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 151 of file mysql_database.php.
{
try
{
if( $this->Connection === false || $ForceReconnect === true )
{
if( $this->Connection !== false )
{
$this->Connection->close();
}
$DBConfigSet =
get_package(
'database::db_config_set' ,
'last' , __FILE__ );
$DBConfigSet->load_config( dirname( __FILE__ ).'/conf/cf_mysql_database' );
$this->Connection = $DBConfigSet->connect( $this );
if( mysqli_connect_error() )
{
throw(
new Exception(
'An error occured while setting connection to the database '.mysqli_connect_error()
)
);
}
}
return( $this->Connection );
}
catch( Exception $e )
{
}
}
| initial_lock |
( |
|
$Tables, |
|
|
|
$Modes |
|
) |
| |
Initial lock.
- Parameters
-
| $Tables | - Tables to block. |
| $Modes | - Blocking modes. |
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
first lock
Definition at line 640 of file mysql_database.php.
{
try
{
$QueryPart = '';
for( $i = 0 ; $i < count( $Tables ) - 1 ; $i++ )
{
$QueryPart .= $Tables[ $i ].' '.$Modes[ $i ].', ';
}
$QueryPart .= $Tables[ count( $Tables ) - 1 ].' '.$Modes[ count( $Tables ) - 1 ];
$this->
query(
'LOCK TABLES '.$QueryPart );
self::$LockedTables = $Tables;
self::$LockModes = $Modes;
}
catch( Exception $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 379 of file mysql_database.php.
{
try
{
$this->
query(
"INSERT INTO $Table ( $Fields ) VALUES ( $Values )" );
}
catch( Exception $e )
{
}
}
Function blocks tables.
- Parameters
-
| $Tables | - Tables to block. |
| $Modes | - Blocking modes. |
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
we already have locked tables
Definition at line 742 of file mysql_database.php.
{
try
{
if( self::$LockedTables === false )
{
}
else
{
for( $i = 0 ; $i < count( $Tables ) ; $i++ )
{
}
}
}
catch( Exception $e )
{
}
}
Function executes query.
- Parameters
-
- Returns
- Query result.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 202 of file mysql_database.php.
{
try
{
$Query = str_replace( 'umx_' , $this->TablenamePrefix , $Query );
$Result = $this->Connection->query( $Query );
if( $this->Connection->errno !== 0 )
{
throw( new Exception( 'An error occured while query execution '.$this->Connection->error ) );
}
return( $Result );
}
catch( Exception $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 243 of file mysql_database.php.
{
try
{
self::$QueryMode = $theQueryMode;
}
catch( Exception $e )
{
}
}
Function rollbacks transaction to savepoint.
- Parameters
-
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 842 of file mysql_database.php.
{
try
{
$this->
query(
'ROLLBACK TO SAVEPOINT '.$Savepoint );
}
catch( Exception $e )
{
}
}
Function sets savepoint.
- Parameters
-
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 812 of file mysql_database.php.
{
try
{
$this->
query(
'SAVEPOINT '.$Savepoint );
}
catch( Exception $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 285 of file mysql_database.php.
{
try
{
$Result = $this->
query(
"SELECT $What FROM $Tables WHERE $Condition" );
}
catch( Exception $e )
{
}
}
Function starts new transaction.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 868 of file mysql_database.php.
{
try
{
$this->
query(
'START TRANSACTION' );
}
catch( Exception $e )
{
}
}
| try_lock_table |
( |
|
$Tables, |
|
|
|
$Modes, |
|
|
|
$i |
|
) |
| |
Function tries to lock table.
- Parameters
-
| $Tables | - Tables to block. |
| $Modes | - Blocking modes. |
| $i | - Cursor. |
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 691 of file mysql_database.php.
{
try
{
$Key = array_search( $Tables[ $i ] , self::$LockedTables );
if( $Key === false )
{
throw( new Exception( "Lock tables error. Invalid lock logic." ) );
}
if( self::$LockedTables[ $Key ] == 'WRITE' )
{
}
else
{
if( $Modes[ $i ] === 'WRITE' && self::$LockModes[ $Key ] === 'READ' )
{
throw( new Exception( "Lock tables error. Invalid lock mode logic." ) );
}
}
}
catch( Exception $e )
{
}
}
Function releases all locks for all tables.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 780 of file mysql_database.php.
{
try
{
self::$LockedTables = false;
self::$LockModes = false;
$this->
query(
'UNLOCK TABLES' );
}
catch( Exception $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 455 of file mysql_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 )
{
}
}
Field Documentation
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 mysql_database.php.
The documentation for this class was generated from the following file: