Public Member Functions |
| | __construct () |
| | set ($Field, $Value) |
| | execute_query_set ($SetOfQueries) |
| | try_connect () |
| | select_condition ($Start=false, $Limit=false, $Field=false, $Order=false, $Condition= '1=1', $NativeTable=false) |
| | add_security_fields ($Fields, $Values, $AddFields=0) |
| | add_special_fields ($Fields, $Values, $AddFields=0) |
| | compile_fields_values (&$Record, $AddFields=0) |
| | create ($TableName, &$Fields, &$Values) |
| | count_of_records ($TableName, $Condition= '1=1') |
| | record_exists ($TableName, $Condition= '1=1') |
| | get_list_of_tables () |
| | get_list_of_fields ($TableName) |
Detailed Description
Class providees routine for database manipulation.
- Author
- Dodonov A.A.
Definition at line 31 of file database_algorithms.php.
Constructor & Destructor Documentation
Constructor.
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 61 of file database_algorithms.php.
{
try
{
$this->Database =
get_package(
'database' ,
'last' , __FILE__ );
$this->Security =
get_package(
'security' ,
'last' , __FILE__ );
}
catch( Exception $e )
{
}
}
Member Function Documentation
| add_security_fields |
( |
|
$Fields, |
|
|
|
$Values, |
|
|
|
$AddFields = 0 |
|
) |
| |
Function adds security fields.
- Parameters
-
| $Fields | - Fields. |
| $Values | - Values. |
| $AddFields | - Additional fields. |
- Returns
- array( $Fields , $Values ).
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 272 of file database_algorithms.php.
{
try
{
{
$Fields [] = 'owner';
}
return( array( $Fields , $Values ) );
}
catch( Exception $e )
{
}
}
| add_special_fields |
( |
|
$Fields, |
|
|
|
$Values, |
|
|
|
$AddFields = 0 |
|
) |
| |
Function adds special fields.
- Parameters
-
| $Fields | - Fields. |
| $Values | - Values. |
| $AddFields | - Additional fields. |
- Returns
- array( $Fields , $Values ).
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 321 of file database_algorithms.php.
{
try
{
{
$Fields [] = 'creation_date';
$Values [] = 'NOW()';
}
{
$Fields [] = 'modification_date';
$Values [] = 'NOW()';
}
{
$Fields [] = 'publication_date';
$Values [] = 'NOW()';
}
}
catch( Exception $e )
{
}
}
| compile_fields_values |
( |
& |
$Record, |
|
|
|
$AddFields = 0 |
|
) |
| |
Function fetches fields and values.
- Parameters
-
| $Record | - Record to insert. |
| $AddFields | - Additional fields. |
- Returns
- array( $Fields , $Values ).
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 375 of file database_algorithms.php.
{
try
{
$Fields = array();
$Values = array();
foreach( $Record as $f => $v )
{
if( $v !== '_no_update' && $f !== 'master_id' && $f !== 'master_type' )
{
$Fields [] = $f;
if( is_array( $v ) || is_object( $v ) )
{
$Values [] = "'".serialize( $v )."'";
}
else
{
$Values [] = "'".$v."'";
}
}
}
}
catch( Exception $e )
{
}
}
| count_of_records |
( |
|
$TableName, |
|
|
|
$Condition = '1 = 1' |
|
) |
| |
Function count of tables in the query.
- Parameters
-
| $TableName | - Name of the table. |
| $Condition | - Records selection condition. |
- Returns
- Count of records.
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 485 of file database_algorithms.php.
{
try
{
$CountOfRecords = $this->Database->select( 'COUNT( * ) AS count_of_records' , $TableName , $Condition );
$CountOfRecords =
get_field( $CountOfRecords[ 0 ] ,
'count_of_records' );
return( $CountOfRecords );
}
catch( Exception $e )
{
}
}
| create |
( |
|
$TableName, |
|
|
& |
$Fields, |
|
|
& |
$Values |
|
) |
| |
Function validates can we connect to the database.
- Parameters
-
| $TableName | - Name of the table. |
| $Fields | - Fields. |
| $Values | - Values. |
- Returns
- Id of the created record.
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 437 of file database_algorithms.php.
{
try
{
$this->Database->lock( array( $TableName ) , array( 'WRITE' ) );
$this->Database->insert( $TableName , implode( ',' , $Fields ) , implode( ',' , $Values ) );
$this->Database->commit();
$id = $this->Database->select( '*' , $TableName , '1 = 1 ORDER by id DESC LIMIT 0 , 1' );
$this->Database->unlock();
return( $id );
}
catch( Exception $e )
{
}
}
| execute_query_set |
( |
|
$SetOfQueries | ) |
|
Execute SQL queries from $SetOfQueries.
- Parameters
-
| $SetOfQueries | - set of SQL queries; |
- Note
- SQL instructions are separated by ";\r\n".
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 119 of file database_algorithms.php.
{
try
{
$SetOfQueries = explode( ";\n" , $SetOfQueries );
foreach( $SetOfQueries as $Query )
{
$this->Database->query( $Query );
$this->Database->commit();
}
}
catch( Exception $e )
{
}
}
| get_list_of_fields |
( |
|
$TableName | ) |
|
Function returns a list of table's columns.
- Parameters
-
- Returns
- List of table's columns names.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 600 of file database_algorithms.php.
{
try
{
$TableName = $this->Security->get( $TableName , 'command' );
$Result = $this->Database->query( "SHOW FIELDS FROM `$TableName`" );
return( $this->Database->fetch_results( $Result ) );
}
catch( Exception $e )
{
}
}
Function returns a list of tables.
- Returns
- A list of tables.
- Exceptions
-
| Exception | - An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 557 of file database_algorithms.php.
{
try
{
$Result = $this->Database->query( 'SHOW TABLES' );
$ListOfTables = $this->Database->fetch_results( $Result );
foreach( $ListOfTables as $i => $TableInfo )
{
$ListOfTables[ $i ] = $TableInfo[ 0 ];
}
return( $ListOfTables );
}
catch( Exception $e )
{
}
}
| record_exists |
( |
|
$TableName, |
|
|
|
$Condition = '1 = 1' |
|
) |
| |
Function checks fo record exists.
- Parameters
-
| $TableName | - Name of the table. |
| $Condition | - Records selection condition. |
- Returns
- true/false.
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 527 of file database_algorithms.php.
{
try
{
}
catch( Exception $e )
{
}
}
| select_condition |
( |
|
$Start = false, |
|
|
|
$Limit = false, |
|
|
|
$Field = false, |
|
|
|
$Order = false, |
|
|
|
$Condition = '1 = 1', |
|
|
|
$NativeTable = false |
|
) |
| |
Function returns condition of records selection.
- Parameters
-
| $Start | - Number of the first record. |
| $Limit | - Count of records limitation. |
| $Field | - Field to sort by. |
| $Order | - Sorting order. |
| $Condition | - Additional conditions. |
| $NativeTable | - Table name. |
- Returns
- Condition of records selection.
- Exceptions
-
| Exception | An exception of this type is thrown. |
- Author
- Dodonov A.A.
Definition at line 209 of file database_algorithms.php.
{
try
{
if( $Start !== false )
{
$Start = $this->Security->get( $Start , 'integer' );
$Limit = $this->Security->get( $Limit , 'integer' );
if( $Field === false )
{
$Field = $NativeTable !== false ? "$NativeTable.id" : 'id';
$Order = 'DESC';
}
else
{
$Field = $this->Security->get( $Field , 'command' );
$Order = $this->Security->get( $Order , 'command' );
$Order = ( $Order === 'ascending' || $Order === 'ASC' ) ? 'ASC' : 'DESC';
}
$Condition = "$Condition ORDER BY $Field $Order LIMIT $Start , $Limit";
}
return( $Condition );
}
catch( Exception $e )
{
}
}
Function sets field.
- Parameters
-
| $Field | - Field name. |
| $Value | - Field value. |
- Author
- Dodonov A.A.
Definition at line 92 of file database_algorithms.php.
{
$this->$Field = $Value;
}
Function validates can we connect to the database.
- Exceptions
-
| true | if the connection was established, false otherwise. |
- Author
- Dodonov A.A.
Definition at line 151 of file database_algorithms.php.
{
try
{
$Obj = $this->Database->get_object( true );
$Obj->get_connection();
return( true );
}
catch( Exception $e )
{
return( false );
}
}
Field Documentation
The documentation for this class was generated from the following file: