116 $Config = explode(
"#" , $ConfigRow );
117 $this->Host = $Config[ 0 ];
118 $this->Username = $Config[ 1 ];
119 $this->Password = $Config[ 2 ];
120 $this->Database = $Config[ 3 ];
121 $this->TablenamePrefix = $Config[ 4 ];
123 $this->Connection = @
new mysqli( $this->Host , $this->Username , $this->Password , $this->Database );
125 catch( Exception $e )
155 if( $this->Connection ===
false || $ForceReconnect ===
true )
157 if( $this->Connection !==
false )
159 $this->Connection->close();
161 $DBConfigSet =
get_package(
'database::db_config_set' ,
'last' , __FILE__ );
162 $DBConfigSet->load_config( dirname( __FILE__ ).
'/conf/cf_mysql_database' );
163 $this->Connection = $DBConfigSet->connect( $this );
165 if( mysqli_connect_error() )
169 'An error occured while setting connection to the database '.mysqli_connect_error()
174 return( $this->Connection );
176 catch( Exception $e )
208 $Query = str_replace(
'umx_' , $this->TablenamePrefix , $Query );
210 $Result = $this->Connection->query( $Query );
212 if( $this->Connection->errno !== 0 )
214 throw(
new Exception(
'An error occured while query execution '.$this->Connection->error ) );
219 catch( Exception $e )
247 self::$QueryMode = $theQueryMode;
249 catch( Exception $e )
285 function select( $What , $Tables , $Condition =
'1 = 1' )
289 $Result = $this->
query(
"SELECT $What FROM $Tables WHERE $Condition" );
293 catch( Exception $e )
325 $RetValues = array();
327 for( $i = 0; $i < $Result->num_rows ; $i++ )
331 $RetValues [] = $Result->fetch_array( MYSQLI_ASSOC );
333 elseif( self::$QueryMode ==
DB_ARRAY )
335 $RetValues [] = $Result->fetch_array( MYSQLI_NUM );
339 $RetValues [] = $Result->fetch_object();
345 return( $RetValues );
347 catch( Exception $e )
379 function insert( $Table , $Fields , $Values )
383 $this->
query(
"INSERT INTO $Table ( $Fields ) VALUES ( $Values )" );
385 catch( Exception $e )
413 function delete( $Table , $Condition =
'1 = 1' )
417 $this->
query(
"DELETE FROM $Table WHERE $Condition" );
419 catch( Exception $e )
455 function update( $Table , $Fields , $Values , $Condition =
'1 = 1' )
461 for( $i = 0 ; $i < count( $Fields ) - 1 ; $i++ )
463 $SubQuery .= $Fields[ $i ].
' = '.$Values[ $i ].
' , ';
465 $SubQuery .= $Fields[ count( $Fields ) - 1 ].
' = '.$Values[ count( $Fields ) - 1 ];
467 $this->
query(
"UPDATE $Table SET $SubQuery WHERE $Condition" );
469 catch( Exception $e )
497 function create( $Table , $FirstIndexField =
'id' )
502 "CREATE TABLE `$Table` ( `$FirstIndexField` INTEGER UNSIGNED NOT NULL DEFAULT NULL ".
503 "AUTO_INCREMENT , PRIMARY KEY ( `$FirstIndexField` ) )"
506 catch( Exception $e )
534 $this->
query(
"DROP TABLE $Table" );
536 catch( Exception $e )
572 function add_column( $Table , $ColumnName , $Type , $Mode =
'NOT NULL AFTER `id`' )
576 $this->
query(
"ALTER TABLE `$Table` ADD COLUMN `$ColumnName` $Type $Mode" );
578 catch( Exception $e )
610 $this->
query(
"ALTER TABLE `$Table` DROP COLUMN `$ColumnName`" );
612 catch( Exception $e )
648 for( $i = 0 ; $i < count( $Tables ) - 1 ; $i++ )
650 $QueryPart .= $Tables[ $i ].
' '.$Modes[ $i ].
', ';
652 $QueryPart .= $Tables[ count( $Tables ) - 1 ].
' '.$Modes[ count( $Tables ) - 1 ];
654 $this->
query(
'LOCK TABLES '.$QueryPart );
656 self::$LockedTables = $Tables;
657 self::$LockModes = $Modes;
659 catch( Exception $e )
695 $Key = array_search( $Tables[ $i ] , self::$LockedTables );
699 throw(
new Exception(
"Lock tables error. Invalid lock logic." ) );
701 if( self::$LockedTables[ $Key ] ==
'WRITE' )
708 if( $Modes[ $i ] ===
'WRITE' && self::$LockModes[ $Key ] ===
'READ' )
710 throw(
new Exception(
"Lock tables error. Invalid lock mode logic." ) );
714 catch( Exception $e )
742 function lock( $Tables , $Modes )
746 if( self::$LockedTables ===
false )
754 for( $i = 0 ; $i < count( $Tables ) ; $i++ )
760 catch( Exception $e )
784 self::$LockedTables =
false;
785 self::$LockModes =
false;
786 $this->
query(
'UNLOCK TABLES' );
788 catch( Exception $e )
816 $this->
query(
'SAVEPOINT '.$Savepoint );
818 catch( Exception $e )
846 $this->
query(
'ROLLBACK TO SAVEPOINT '.$Savepoint );
848 catch( Exception $e )
872 $this->
query(
'START TRANSACTION' );
874 catch( Exception $e )
898 $this->
query(
'COMMIT' );
900 catch( Exception $e )