Download the PHP package wscore/dbaccess without Composer
On this page you can find all versions of the php package wscore/dbaccess. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dbaccess
ScoreDB
A simple Database Access Manager and Data Access Object class.
This package provides a quick access for
- ExtendedPdo and ConnectionPools from AuraPHP/Sql package,
- slick query composition using ScoreSql, and
- a simple Dao (Database Access Object).
license
MIT License
Sample Usage
configuration
Uses static class as a gateway (aka facade) to database manager ( class).
Use method to configure the db connection.
Please refer to Aura/Sql components for details of the each configuration.
Specify in the configuration to connect to different databases for reading and writing.
get connection (i.e. Pdo)
getting the Pdo object for db connection. The in Aura/Sql is returned.
returns the connection for reading if write connection is not set.
get named connection
Configure different database connection using names.
Querying Database
Use to get a query object to access database. Please refer to ScoreSql to find out how to manipulate the query.
The maybe omitted if the default connection is used.
EntityObject
As default, the Dao object returns the found database record as class. This class has a reference to the Dao object to provide many useful functions while keeping the code base to a minimum size.
some functions are:
- mutating values to an object (or back).
- accessing data as a property, or as array.
- finding the modified data.
- get the primary key.
- get the relation objects.
ActiveRecord
Dao can return object as ActiveRecord class, as
The ActiveRecord class will provide more functions added to the EntityObject described above, such as,
- save to database.
- delete itself from database.
- immunize the access to database.
Data Access Object
sample dao class
Extend class.
table name and primary key
specify table name as , and primary key name as .
If these are not set, class name is used as table name, and is used as key name.
timestamps
Use to indicate stamps: for at the creation of data, and for updating and creation time.
Specify the date format if different
using DaoTrait
alternatively, use DaoTrait to create dao object using other query class. as such,
accessing database
Use $dao object just like a Query object in WScore.SqlBuilder.
selecting:
or use $dao object as an iterator.
updating:
or,
inserting:
or,
Scopes and Events in Dao
scopes
Scopes are functions starting with . In the scope function, influence the query to get what is desired.
hooks
Hook methods starts with , event name, and end with .
filters
Filter methods starts with , event name, and end with .
Filters are for modifying the input or output; make very sure that filters return what is given (or modified value) or nothing will happen.
hook objects
The Dao class may become too large with lots of scopes and event hooks. To simplify the dao class, these methods can be transferred to another object (hook object) using method, such as:
available events
whenever accessing database, start with , and followed by .
- selecting, selected,
- loading, loaded,
- counting, counted,
- inserting, inserted,
- updating, updated,
- deleting, deleted,
hidden (or already used) events:
- createStamp, updateStamp:
for adding timestamps to data when inserting or updating data.
Relation
ScoreDB provides simple relationship classes as,
- HasOne,
- HasMany, and
- HasJoin.
Using Relation
In your Dao class, create methods like'
to set new relation,
WISHES WISHES WISHES
transaction
for transaction, use the Pdo (ExtendedPdo)'s transaction method.