Download the PHP package octacondeveloper/php-orm without Composer
On this page you can find all versions of the php package octacondeveloper/php-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-orm
PHP-ORM
This is a light weight ORM for core PHP applications that supports MySQL, Postgres and Sqlite database engine out of the box.
Badges
Installation
Install PHP-ORM with composer
Env
Usage/Examples
Or You can use it as a Model Extension
Then in your class you can call the User Class with the Query methods
Documentation
PHP-ORM provides you with two distinct methods of interactions with methods. Which can be through
Query
This options allow to specify the table name directly while making the calls and it has several methods. A quick example of it usage is
Available methods
insert(array $data)
Create a new record into the selected table
insertBulk(array $data);
Insert bulk records at once
all();
Fetch all records on the table
first();
Fetch the first record on the table
last(string $column);
Fetch the last record on the datable, If a column is not provided, it would order it based on the primaryKey or based on the first availablecolumn on the table
rawQuery(string $sqlQuery);
This allows you to pass direct sql string to the Query instance
where(string $column, string $operand, string $value);
Add a query condition
andWhere(string $column, string $operand, string $value);
Add another compulsory query condition, this comes after an initial "where" method has been called
orWhere(string $column, string $operand, string $value);
Add another optional query condition, this comes after an initial "where" method has been called
orderBy(string $column, string $order);
Order records based on column either in ASC or DESC. Default order is ASC
count(string $column = null, string $value, string $operand);
Counts the number of records available on the table based on provided column and condition. If no parameters are passed, it count count the total records without any condition
max(string $column);
Get the maximum
min(string $column);
Get the minimum
update(array $data);
Update a record
delete();
Delete a record
begingTransaction();
Begin a transaction
commitTransaction();
Commit a transaction
rollbackTransaction();
Rollback a transaction
transaction($transaction);
Start a DB trabsaction session
withOne(string $table, string $foreignKey, string $primaryKey = 'id')
Fetch a one to one model relationship between two models
withMany(string $table, string $foreignKey, string $primaryKey = 'id')
Fetch a one to many model relationship between two models
Model
The Model approach allows you to create a class for your table and extends the model base class. This allows you to have other custom SQL related transaction in your class. It can used as follows:
Defining the table variable is optional. By default the Package gets your class name and assumes the corresponding table name to it. Take for example
Available methods
insert(array $data)
Create a new record into the selected table
insertBulk(array $data);
Insert bulk records at once
all();
Fetch all records on the table
first();
Fetch the first record on the table
last(string $column);
Fetch the last record on the datable, If a column is not provided, it would order it based on the primaryKey or based on the first availablecolumn on the table
where(string $column, string $operand, string $value);
Add a query condition
andWhere(string $column, string $operand, string $value);
Add another compulsory query condition, this comes after an initial "where" method has been called
orWhere(string $column, string $operand, string $value);
Add another optional query condition, this comes after an initial "where" method has been called
orderBy(string $column, string $order);
Order records based on column either in ASC or DESC. Default order is ASC
count(string $column = null, string $value, string $operand);
Counts the number of records available on the table based on provided column and condition. If no parameters are passed, it count count the total records without any condition
max(string $column);
Get the maximum
min(string $column);
Get the minimum
update(array $data);
Update a record
delete();
Delete a record
withOne(string $table, string $foreignKey, string $primaryKey = 'id')
Fetch a one to one model relationship between two models
withMany(string $table, string $foreignKey, string $primaryKey = 'id')
Fetch a one to many model relationship between two models
Method Chaining
The package allows method chaining as most of the methods wont return a result until it's chained to certian methods.
Authors
Contributing
Contributions are always welcome! This is an Open Source library and Pull Requests would be extremely welcome.