Download the PHP package axisstudios/db-record without Composer
On this page you can find all versions of the php package axisstudios/db-record. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download axisstudios/db-record
More information about axisstudios/db-record
Files in axisstudios/db-record
Package db-record
Short Description Manage database records. This library is part of the SoloProyectos PHP API.
License MIT
Informations about the package db-record
DbRecord
Introduction
DbRecord
is a library that allows us to operate databases without manually execute SQL statements. Unlike other similar libraries, DbRecord allows us to operate on multiple tables at the same time, resulting in a more concise and clear code.
Installation
This package is provided via composer package manager. Just create a composer.json
file and execute the following command in the same directory:
See Basic Usage for more info.
Database requirements
This library can operate any MySQL database, with the only condition that each table MUST have a primary key composed by a single auto-increment column. By default, the primary key is called ID
, but you can change it from the constructor.
Basic examples: insert(), update(), select() and delete()
We use the DbRecordTable
class to perform basic operations.
Inserting records
To insert records, we ommit the id
parameter from the constructor:
Updating records
Updates the record ID=1:
Inserting/Updating records
You can insert or update a record in the same line. For example:
Selecting records
Selects the record ID=1:
Deleting records
Delete the record ID=1:
For a more complex example see test1.php.
General example: Accessing several tables at the same time
Let's say that we have a main table (table0
) and three secondary tables (table1
, table2
and table3
). The three tables are 'left joined' to the main table through the columns table1_id
, table2_id
and table3_id
. That is:
Instead of operating on tables individually, we can do it at the same time. The following example selects a record (ID = 1) and updates or inserts records on table1
, table2
and table3
:
The following example selects a record (ID = 1) and retrieves columns from table0
, table1
, table2
and table3
at the same time:
For a more complex example see test2.php.
Column path expressions
In the previous examples we accessed the title
column of table1
through the following expression: table1.title
. The general format is as follows:
We can omit id
and table0_id
, as they are taken by default. So the previous expression can by simplified as follows:
Let's imagine a more complex example. Let's say that table2
depends on table1
which, at the same time, depends on table0
. That is:
In that case, we use the following code to access the table1
and table2
columns:
The previous expressios are simplified versions of the general expressions:
We can omit id
and <table>_id
, as they are taken by default.
For more complex examples see test5.php
All versions of db-record with dependencies
soloproyectos-php/db Version ~1.1
soloproyectos-php/array Version ~1.0
soloproyectos-php/text Version ~1.0