ultimix

- Main Page
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Data Fields

Public Member Functions | Data Fields | Static Public Attributes
mysql_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)
| initial_lock ($Tables, $Modes)
| try_lock_table ($Tables, $Modes, $i)
| lock ($Tables, $Modes)
| unlock ()
| savepoint ($Savepoint)
| rollback ($Savepoint)
| transaction ()
| commit ()

## Data Fields
| $Connection = false
| $Host
| $Username
| $Password
| $Database
| $TablenamePrefix

## 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 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 )
{
$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 894 of file mysql_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 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 )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $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
{
$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 413 of file mysql_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 530 of file mysql_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 606 of file mysql_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 321 of file mysql_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_ARRAY )
{
$RetValues [] = $Result->fetch_array( MYSQLI_NUM );
}
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.

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 )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $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 )
{
$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 379 of file mysql_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.

we already have locked tables

Definition at line 742 of file mysql_database.php.

{
try
{
if( self::$LockedTables === false )
{
$this->initial_lock( $Tables , $Modes );
}
else
{
for( $i = 0 ; $i < count( $Tables ) ; $i++ )
{
$this->try_lock_table( $Tables , $Modes , $i );
}
}
}
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.

Exceptions

  Exception | - An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 202 of file mysql_database.php.

{
try
{
$this->get_connection();
$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 )
{
$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 243 of file mysql_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 842 of file mysql_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 812 of file mysql_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 285 of file mysql_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 868 of file mysql_database.php.

{
try
{
$this->query( 'START TRANSACTION' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $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' )
{
/* nop */
}
else
{
/*if we are trying to change lock from READ to WRITE then we get an error */
if( $Modes[ $i ] === 'WRITE' && self::$LockModes[ $Key ] === 'READ' )
{
throw( new Exception( "Lock tables error. Invalid lock mode logic." ) );
}
}
}
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 780 of file mysql_database.php.

{
try
{
self::$LockedTables = false;
self::$LockModes = false;
$this->query( 'UNLOCK TABLES' );
}
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 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 )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Field Documentation

$Connection = false

Connection object.

Author
  Dodonov A.A.

Definition at line 38 of file mysql_database.php.

$Database

Definition at line 91 of file mysql_database.php.

$Host

DB connection parameters.

Author
  Dodonov A.A.

Definition at line 88 of file mysql_database.php.

$LockedTables = false
| static

List pf blocked tables.

Author
  Dodonov A.A.

Definition at line 50 of file mysql_database.php.

$LockModes = false
| static

Lock modes.

Author
  Dodonov A.A.

Definition at line 62 of file mysql_database.php.

$Password

Definition at line 90 of file mysql_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 mysql_database.php.

$TablenamePrefix

Definition at line 92 of file mysql_database.php.

$Username

Definition at line 89 of file mysql_database.php.

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

- packages/database/packages/mysql_database/mysql_database.php