Download the PHP package mfurman/pdomodel without Composer
On this page you can find all versions of the php package mfurman/pdomodel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pdomodel
PDO Model
PDO access class with PDO model - version 1.0.3
Changes from version 1.0.3
- minor corrections in code to version 1.0.2,
- minor corrections in interfaces for exists classes,
- added simply logger method,
- added check for PDO singleton instance,
- alignment for variable names,
Changes from version 1.0.2
- changed database table declaration in model - now You have to declare table in constructor as a parent property after PDOAccess instance,
- changed execution protected methods in model - now You don't have to set name of table as parameter in execute method - table is declared by constructor,
- added two public methods - "set_table" and "get_table" - methods are setter and getter for change declared name of table in constructor during model life,
- changed way of execution public method "exist" - now You can set a table for this method as the last calling parameter, if You don't declare this parameter method will execute on exist declared table by constructor,
Simple Instalation
Just use composer for install new dependency:
Simple Usage
First set config for MySQL database (it can be simple array):
Then initialize singletone instance of PDOAccess by execute static method GET:
At this moment You have one instance of PDO Access class in Your app, You can get this instance whenever You want.
Now You can create simply model by extending dataDb class (this class has state of specific model):
Model example:
When You created models, You can create some repositories. In repositories You have control at database transactions and commits.
Repository example:
Class dataDb has builded methods, which we can use in our model or repository.
Public methods (can be use in model and repository):
Constructor - parametres: (PDOModel-singletone, database_table, commit, flag to register any saves to database in log table)
If You would like to register activity in log table You have to create 'general_log' table (look at the end). If not, just set this toggle to 'false' or do't use it - it's false by default
set_commit - toggle to change auto commit - default by 'true'
reset - reset state of model, it doesn't reset table name
set_table - change or set database table for model (new method)
get_table - return actual database table name set in model (new method)
is - inform about state - is hydrated or not - return 'true/false'
set - set data to model
get - get value by name from model
get_flat - get array of specific data as one dimension array
del - remove some value from state by name
begin - start transaction when autocommit is false
commit - commit started transaction when autocommit is false
Protected methods (can be use in model only):
read - read data from table, hydrate state of model - execute (commit) - return model object, can be chaining
$this->read(table, columns, where, order, limit) :object
insert - insert data to database table - execute (commit) - return new ID of created row
update - update data to existing row in table - execute (commit) - return model object, can be chaining
update_where - update data to existing row in table - execute (commit) - return model object, can be chaining
delete_where - delete data from table - execute (commit) - return model object, can be chaining
exists - check if data exists in database - return true/false
$this->exists(table,['name1' =>'value1', 'name2' => 'value2', ...], where(in SQL), table (optional))
General log table structures
General log table is used when we have set session between user and server. It using session data to recognize existing user and his activity. We have to set two session data for logged user:
General log table must have these specyfic columns and name:
table name: 'general_log'
columns:
- 'date': timestampler,
- 'user_id': int - $_SESSION['user_id']
- 'user_name': string - $_SESSION['user_name']
- 'method': string - (INSERT, UPDATE, DELETE - methods that executed on database)
- 'value': string - (SQL query that the user generated)
All data in general log will be automatically filled when flag 'log_rec' is set to 'true'.
Enjoy.
License :old_key:
Under license (MIT, Apache etc)
MIT © Michał Furman