- version 1.0
- author Alfasado Inc. <webmaster@alfasado.jp>
- copyright 2017 Alfasado Inc. All Rights Reserved.
- PHP version requirements to PHP 5.6 or 7 or later.
- Supports UTF-8 encoded text only.
- MySQL version 5.6 or later.
<?php
require_once( 'class.PADO.php' );
$db = new PADO();
$db->configure_from_json( 'db-config.json.cgi' );
$objects = $db->model( 'entry' )->load();
foreach ( $objects as $obj ) {
echo $obj->title, '<br />';
}
$entry = $db->model( 'entry' )->new();
$entry->title( 'PHP Alternative Database Object' );
$entry->date( date( 'YmdHis' ) );
$entry->save();
Initialize a Database Connection.
- array $config: Array for set class properties.
Required property : dsn or driver, dbname, dbhost, dbuser, dbpasswd, dbport and dbcharset.
Get instance of class PADO.
- object $pado : Object class PADO.
Set properties from JSON.
- string $json: JSON file path.
Initializing the model. When class exists model use it. or PADO + driver name(e.g.PADOMySQL) use it. Otherwise use PADOBaseModel.
- string $model : Name of model.
- object $class : Class model object.
Register plugin callback.
- string $model : Name of model.
- string $kind : Kind of callback (pre_save, post_save, pre_delete, post_delete, save_filter, delete_filter or pre_load).
- string $meth : Function or method name.
- int $priority : Callback priority.
- object $class : Plugin class object.
Run callbacks.
- array $cb : An array of string callback name, string sql and array values.
- string $model : Name of model.
- object $obj : Model object.
- bool $needle : If specified and save_filter or delete_filter callbacks returns false, cancel it.
Load object.
- string $model : Name of model.
- mixed $terms : Numeric ID or an array should have keys matching column names and the values are the values for that column.
- array $args : Search options.
- string $cols : Get columns from records. Comma-separated text or '*'.
- string $extra : String to add to the WHERE statement. Insufficient care is required for injection.
- array $objects : An array of objects or single object(Specified Numeric ID).
Quotes a string for use in a query.
- string $str : String to quote.
- string $quoted : Quoted string.
stash: Where the variable is stored.
- string $name : Name of set or get variable to(from) stash.
- mixed $value: Variable for set to stash.
- mixed $var : Stored data.
Quotes a string for like statement.
- string $str : String to quote.
- bool $start : Add '%' before $str.
- bool $end : Add '%' after $str.
- string $quoted : Quoted string.
Clear cached objects or valiable. If model is omitted, all caches are cleared.
- string $model : Name of model.
Table prefix.
Column name prefix. You can specify wild card strings <table> or <model>.
Index name prefix. You can specify wild card strings <table> or <model>.
Column name of Primary key.
$debug: 1.error_reporting( E_ALL ) / 2.debugPrint error. /3.debugPrint SQL statement.
If specified migrate db from $pado->scheme[ $model ].
- version 1.0
<?php
$db->json_model = true;
$entry = $db->model( 'entry' );
$terms = ['title' => 'Hello', 'description' => 'This is description of Hello.'];
$args = ['limit' => 10, 'offset' => 10, 'sort' => 'id', 'direction' => 'ascend'];
// Load Objects.
$entries = $entry->load( $terms, $args );
foreach ( $entries as $entry ) {
echo $obj->title, '<br />';
}
// Like Statement.
$phrase = $db->escape_like( 'PADO' );
$terms['body' => ['like' => $phrase] ];
$entries = $entry->load( $terms );
// Count Objects.
$count = $entry->count( $terms );
// New Object.
$entry = $entry->new();
$entry->title( 'New Entry' );
$entry->set_values(
['body' => 'This is body of new Entry.',
'date' => date( 'YmdHis' ) ]
);
$entry->save();
// Delete Object.
$entry = $entry->load( 1 );
$entry->remove();
{
"column_defs": {
"id": {
"type": "int",
"size": 11,
"not_null": 1
},
"title": {
"type": "string",
"size": 255,
"not_null": 1
},
"body": {
"type": "text"
},
"description" {
"type": "text"
},
"date": {
"type": "datetime"
}
},
"indexes": {
"PRIMARY": "id",
"title": "title",
"date": "date"
}
}
- array $params : An array for column names and values for assign.
- object $object : New object.
Load object.
- mixed $terms : Numeric ID or an array should have keys matching column names and the values are the values for that column.
- array $args : Search options.
- string $cols : Get columns from records. Comma-separated text or '*'.
- string $extra : String to add to the WHERE statement. Insufficient care is required for injection.
- array $objects : An array of objects or single object(Specified Numeric ID).
Load object matches the params. If no matching object is found, return new object assigned params.
- array $params: An array for search or assign.
- object $obj : Single object matches the params or new object assigned params.
Getting the count of a number of objects.
- array $terms : The hash should have keys matching column names and the values are the values for that column.
- int $count : Number of objects.
The model has column or not.
- string $name : Column name.
- bool $has_column : Model has column or not.
- mixed $terms : The hash should have keys matching column names and the values are the values for that column.
- array $args : Columns for grouping. (e.g.['group' => ['column1', ... ] ])
- array $result : An array of conditions and 'COUNT(*)'.
- See load method.
- object $sth : PDOStatement.
INSERT or UPDATE the object.
- bool $success : Returns true if it succeeds.
Alias for save.
DELETE the object.
- bool $success : Returns true if it succeeds.
Alias for remove.
Get table scheme from JSON file and set to $db->scheme[ $model ].
- string $model : Name of model.
Get table scheme from database and set to $db->scheme[ $model ].
- string $model : Name of model.
- string $table : Name of table.
- string $colprefix : Column prefix.
- bool $needle : If specified receive results(array).
- array $scheme : If $needle specified.
Create new table from scheme.
- string $model : Name of model.
- string $table : Name of table.
- array $scheme : An array of column definition and index definition.
Get an array of column names and values.
- array $key-values : Column names and values.
Set column names and values from an array.
- array $params : The hash for assign.
Get column names and values except model properties.
Upgrade database scheme.
- string $table : Name of table.
- array $upgrade : Scheme information of update columns.
- string $colprefix : Column name prefix.
bool $success : Returns true if it succeeds.
Compare the schema definition with the actual schema.
- string $model : Name of model.
- string $table : Name of table.
- string $colprefix : Column prefix.
- array $diff : Difference in array (['column_defs' => $upgrade_cols, 'indexes' => $upgrade_idxs ]).
Validate keys and values.
- array $values : An array for sanitize.
- array $values : Sanitized an array.
Ymd to Y-m-d
His to H:i:s
YmdHis to Y-m-d H:i:s
Y-m-d H:i:s to YmdHis
- version 1.0
PADOMySQL::_engine('InnoDB')
Storage engine.