Download the PHP package wepesi/orm without Composer
On this page you can find all versions of the php package wepesi/orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package orm
Wepesi-ORM
Lightweight and simple Object Relational Mapping
or ORM
.
OVERVIEW
Only MySQL is supported and developed using PHP Data Object
orPDO
,but does not support CLI or Migration.
you should have PDO
extension activated on your php.ini ;
Design by using Prepared Statements.
Prepared Statements protect from SQL injection, and are very important for web application security.
CONFIGURATION
In order to interact with the database, you should provide all required information.
To create an instance you should provide database configuration such host
,db_name
,username
and password
,
you can get instance of DB buy call getInstance
method to get a singleton and take array config as parameters.
Now you have singleton of the database connection.
INTEGRATION
The Module help as some method build to help
select
=>get
insert
=>insert
update
=>update
delete
=>delete
-
and
transaction
. -
get
method is corresponding toSELECT
, it helps to request the database, it as several chained method to help make request more interesting. - in the
get
method we have the first parameter witch is thetable_name
, then we call theresult()
method to execute yourquery
and get result. the corresponding sql is:
in case you want to select specific field and apply a condition.
the corresponding SQL
- use
field
method to precise what are the field you want to get, all parameters should be passed on a simple array, - use
where
method to add condition on the request and to use where method there is rule to follow. an array parameter to pass:- on the first position is the name of the field name as string,
- on the second position is operation
'<', '<=', '>', '>=', '<>', '!=', 'like'
, this only supported condition for more conditional better to write a [*QUERY](sql request
). - The third position is the value of your condition,
- and the forth position is for the operator
and
,or
andnot
, by default itand
, and it is required whene there is multiple conditiontions.
This is not all, you can LIMIT
, OFFSET
,groupBY
,orderBy
,ASC
,DESC
Notes:
in case there is problem as error
method can be called to check if there is any error.
Sometimes you want to count record instead if listing them, count
method is part of get with return an object count.
use count object to access the value return.
insert
is used to record data. the method take table name as parameter, use field method to pass data to be saved. in case your information are correct thedb
instance you can calllastId
method to get the id of the inserted record.
the corresponding sql look like
- DELETE
delete
when you need to delete a record, this is the module to use. the same way you write where condition onget
method is supported only for delete. it will return and arrayarray("delete" => true)
when the operation success.
corresponding sql:
update
when you need to update a record, this is the module to use. the same way you write where condition ondelete
method is supported only for delete. callrowCount
method to get the number of record updated. You should callfield
method to specify witch field to be updated.
corresponding sql:
query
: In case you have complex query,then you can use it.
the example bellow describe how it can be used. with the query
method use the result()
method to get the result.
Transaction
For so many reasons you would like to implement a transaction in case one of your operation failed.
Take caution only InnoDB
support transaction in order to see the result you should be sure your ENGINE
is innoDB,
in case you are not sure about the database engine you can convert your tables only with convertMyISAMToInnoDB
method.
That method will help convert MyISAM
engine to InnoDB
.
There are two ways to use transaction as been defined.
you can manage by your own how, end when to apply transaction or use a builtin transaction
method.
It is recommended to use try catch in or to fulfil the operation.
-
pdo transaction
The transaction has tree method to used in order to work properly, we have:
beginTransaction
: this method is used to start a transaction, and is shoudl be place at the beginning operation where the transaction will occur.commit
: used this method when the operation succeeds.-
rollBack
: is used to cancel all the operation. -
Transaction as callback
method support closure method to be passed as parameter.
You don't need to manage every situation of the transaction, the method help you the focus implementation, and it will do the job for you. - hope you enjoy. The ORM does not have join method or inclusion, on case to do that better to use *QUERY method.