16 define(
'CREATION_DATE' , 1 );
17 define(
'MODIFICATION_DATE' , 2 );
18 define(
'PUBLICATION_DATE' , 4 );
19 define(
'OWNER' , 8 );
65 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
66 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
92 function set( $Field , $Value )
94 $this->$Field = $Value;
123 $SetOfQueries = explode(
";\n" , $SetOfQueries );
125 foreach( $SetOfQueries as $Query )
127 $this->Database->query( $Query );
128 $this->Database->commit();
131 catch( Exception $e )
155 $Obj = $this->Database->get_object(
true );
157 $Obj->get_connection();
161 catch( Exception $e )
210 $Order =
false , $Condition =
'1 = 1' , $NativeTable =
false )
214 if( $Start !==
false )
216 $Start = $this->Security->get( $Start ,
'integer' );
217 $Limit = $this->Security->get( $Limit ,
'integer' );
219 if( $Field ===
false )
221 $Field = $NativeTable !==
false ?
"$NativeTable.id" :
'id';
226 $Field = $this->Security->get( $Field ,
'command' );
227 $Order = $this->Security->get( $Order ,
'command' );
228 $Order = ( $Order ===
'ascending' || $Order ===
'ASC' ) ?
'ASC' :
'DESC';
231 $Condition =
"$Condition ORDER BY $Field $Order LIMIT $Start , $Limit";
234 return( $Condition );
236 catch( Exception $e )
276 if( $AddFields &
OWNER )
279 $Fields [] =
'owner';
283 return( array( $Fields , $Values ) );
285 catch( Exception $e )
327 $Fields [] =
'creation_date';
328 $Values [] =
'NOW()';
332 $Fields [] =
'modification_date';
333 $Values [] =
'NOW()';
337 $Fields [] =
'publication_date';
338 $Values [] =
'NOW()';
343 catch( Exception $e )
382 foreach( $Record as $f => $v )
384 if( $v !==
'_no_update' && $f !==
'master_id' && $f !==
'master_type' )
388 if( is_array( $v ) || is_object( $v ) )
390 $Values [] =
"'".serialize( $v ).
"'";
394 $Values [] =
"'".$v.
"'";
401 catch( Exception $e )
437 function create( $TableName , &$Fields , &$Values )
441 $this->Database->lock( array( $TableName ) , array(
'WRITE' ) );
443 $this->Database->insert( $TableName , implode(
',' , $Fields ) , implode(
',' , $Values ) );
444 $this->Database->commit();
446 $id = $this->Database->select(
'*' , $TableName ,
'1 = 1 ORDER by id DESC LIMIT 0 , 1' );
449 $this->Database->unlock();
453 catch( Exception $e )
489 $CountOfRecords = $this->Database->select(
'COUNT( * ) AS count_of_records' , $TableName , $Condition );
491 $CountOfRecords =
get_field( $CountOfRecords[ 0 ] ,
'count_of_records' );
493 return( $CountOfRecords );
495 catch( Exception $e )
533 catch( Exception $e )
561 $this->Database->query_as(
DB_ARRAY );
562 $Result = $this->Database->query(
'SHOW TABLES' );
563 $ListOfTables = $this->Database->fetch_results( $Result );
565 foreach( $ListOfTables as $i => $TableInfo )
567 $ListOfTables[ $i ] = $TableInfo[ 0 ];
570 return( $ListOfTables );
572 catch( Exception $e )
604 $TableName = $this->Security->get( $TableName ,
'command' );
607 $Result = $this->Database->query(
"SHOW FIELDS FROM `$TableName`" );
609 return( $this->Database->fetch_results( $Result ) );
611 catch( Exception $e )