Download the PHP package asko/orm without Composer
On this page you can find all versions of the php package asko/orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package orm
ORM
A object relational mapper with a query builder and out of box support for MySQL databases.
Installation
Set-up
To start with create your base model class that your actual data models will be extending, like so:
And then you can create all your data models like this:
And woalaa, you have an ORM mapping data classes to tables in the database all with full type support (works especially well with PHPStan).
Note that the $_identifier
should match the name of the primary key column, which in the above case is id
, and the $_table
should match the name of the database table, naturally. The other properties here represent the columns of the table, these will be populated by the ORM automatically when querying data and have to have the Column
attribute.
Querying
You can query for data using the numerous query builder methods built into ORM.
An example query looks like this:
Although because we use the primary key identifier to search for the user, the above could be simplified as:
All query methods
where
Where clause to filter the results.
Usage:
andWhere
Same as where
but with AND
operator.
Usage:
orWhere
Same as where
but with OR
operator.
Usage:
orderBy
Order the results by a column.
Usage:
limit
Limit the number of results.
Usage:
offset
Offset the results.
Usage:
join
Join another table.
Usage:
leftJoin
Join another table with a left join.
Usage:
rightJoin
Join another table with a right join.
Usage:
innerJoin
Join another table with an inner join.
Usage:
outerJoin
Join another table with an outer join.
Usage:
raw
Add a raw SQL to the query.
Usage:
get
Get all the results.
Usage:
first
Get the first result.
Usage:
last
Get the last result.
Usage:
Creating
To create a new record in the database, you can do the following:
Updating
To update a record in the database, you can do the following:
Deleting
To delete a record in the database, you can do the following:
Creating a connection driver
ORM comes with the MySQL driver already built in, but if you wish to extend the ORM to support other databases, you can do so by creating a new driver class that implements the ConnectionDriver
interface, and if you need to also build a new query builder due to syntax differences with the MySQL query builder, you can do so by creating a new query builder class that implements the QueryBuilder
interface.