Download the PHP package josantonius/database without Composer
On this page you can find all versions of the php package josantonius/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
PHP Database library
Versión en español
SQL database management to be used by several providers at the same time.
- Requirements
- Installation
- Quick Start
- Get connection
- CREATE TABLE
- SELECT
- INSERT INTO
- UPDATE
- REPLACE
- DELETE
- TRUNCATE TABLE
- DROP TABLE
- Supported datatypes for prepared statements
- Tests
- Sponsor
- License
Requirements
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
Installation
The preferred way to install this extension is through Composer.
To install PHP Database library, simply:
composer require Josantonius/Database
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
composer require Josantonius/Database --prefer-source
You can also clone the complete repository with Git:
git clone https://github.com/Josantonius/PHP-Database.git
Or install it manually:
Download Database.php, Provider.php, PDOprovider.php, MSSQLprovider.php and DBException.php:
wget https://raw.githubusercontent.com/Josantonius/PHP-Database/master/src/Database.php
wget https://raw.githubusercontent.com/Josantonius/PHP-Database/master/src/Provider/Provider.php
wget https://raw.githubusercontent.com/Josantonius/PHP-Database/master/src/Provider/PDOprovider.php
wget https://raw.githubusercontent.com/Josantonius/PHP-Database/master/src/Provider/MSSQLprovider.php
wget https://raw.githubusercontent.com/Josantonius/PHP-Database/master/src/Exception/DBException.php
Get connection
- Get connection
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$id | Database unique ID. | string | Yes | |
$provider | Name of provider class. | string | No | null |
$host | Database host. | string | No | null |
$user | Database user. | string | No | null |
$name | Database name. | string | No | null |
$password | Database password . | string | No | null |
Attribute | Key | Description | Type | Required | Default |
---|---|---|---|---|---|
$settings | Database options. Once the connection is made, this configuration will be available in the database connection object: $db->settings. | array | No | null | |
$settings | 'port' | Database port. | string | No | |
$settings | 'charset' | Database charset. | string | No |
# Return (object) → object with the connection
Query
- Process query and prepare it for the provider
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$query | Query. | string | Yes | |
$statements | Statements. | array | No | null |
$result | Query result; 'obj', 'array_num', 'array_assoc', 'rows', 'id'. | string | No | 'obj' |
# Return (mixed) → result as object, array, int...
# throws [DBException] → invalid query type
CREATE TABLE
- CREATE TABLE statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
$data | Column name and configuration for data types. | array | Yes | ||
table() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
foreing() | Set foreing key. | method | No | ||
$id | Column id. | string | Yes | ||
reference() | Set reference for foreing keys. | method | No | ||
$table | Table name. | array | Yes | ||
on() | Set database table name. | method | No | ||
$table | Table name. | array | Yes | ||
actions() | Set actions when delete or update for foreing key. | method | No | ||
$action | Action when delete or update. | array | Yes | ||
engine() | Set table engine. | method | No | ||
$type | Engine type. | string | Yes | ||
charset() | Set table charset. | method | No | ||
$type | Charset type. | string | Yes | ||
execute() | Execute query. | method | Yes |
# Return (boolean)
SELECT
- SELECT statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
$columns | Column/s name. | mixed | No | '*' | |
from() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
where() | Where clauses. | method | No | ||
$clauses | Column name and value. | mixed | Yes | ||
$statements | Statements. | array | No | null | |
order() | Order. | method | No | ||
$type | Query sort parameters. | string | Yes | ||
limit() | Limit. | method | No | ||
$number | Number. | int | Yes | ||
execute() | Execute query. | method | Yes | ||
$result | Query result; 'obj', 'array_num', 'array_assoc', 'rows'. | string | No | 'obj' |
# Return (mixed) → query result (object, array, int...) or rows affected
INSERT INTO
- INSERT INTO statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
$data | Column name and value. | array | Yes | ||
$statements | Statements. | array | No | null | |
in() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
execute() | Execute query. | method | Yes | ||
$result | Query result; 'rows', 'id'. | string | No | 'rows' |
# Return (int) → rows affected or last row affected ID
UPDATE
- UPDATE statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
$data | Column name and value. | array | Yes | ||
$statements | Statements. | array | No | null | |
in() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
where() | Where clauses. | method | No | ||
$clauses | Column name and value. | mixed | Yes | ||
$statements | Statements. | array | No | null | |
execute() | Execute query. | method | Yes |
# Return (int) → rows affected
REPLACE
- Replace a row in a table if it exists or insert a new row if not exist
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
$data | Column name and value. | array | Yes | ||
$statements | Statements. | array | No | null | |
from() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
execute() | Execute query. | method | Yes | ||
$result | Query result; 'rows', 'id'. | string | No | 'rows' |
# Return (int) → rows affected or last row affected ID
DELETE
- DELETE statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
$data | Column name and value. | array | Yes | ||
$statements | Statements. | array | No | null | |
from() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
where() | Where clauses. | method | No | ||
$clauses | Column name and value. | mixed | Yes | ||
$statements | Statements. | array | No | null | |
execute() | Execute query. | method | Yes |
# Return (int) → rows affected
TRUNCATE TABLE
- TRUNCATE TABLE statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
table() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
execute() | Execute query. | method | Yes |
# Return (boolean)
DROP TABLE
- DROP TABLE statement
Method | Attribute | Description | Type | Required | Default |
---|---|---|---|---|---|
table() | Set database table name. | method | Yes | ||
$table | Table name. | string | Yes | ||
execute() | Execute query. | method | Yes |
# Return (boolean)
Quick Start
To use this class with Composer:
Or If you installed it manually, use it:
Supported datatypes for prepared statements
Boolean
- bool
- boolean
Null
- null
Integer numbers
- int
- integer
Text strings
- str
- string
If any type of data that does not match the aboves, it will be validated as a string.
If no data type is specified, the data type will not be validated in the prepared query.
Tests
To run composer and to execute the following:
git clone https://github.com/Josantonius/PHP-Database.git
cd PHP-Database
composer install
Run unit tests with PHPUnit:
composer phpunit
Run PSR2 code standard tests with PHPCS:
composer phpcs
Run PHP Mess Detector tests to detect inconsistencies in code style:
composer phpmd
Run all previous tests:
composer tests
Sponsor
If this project helps you to reduce your development time, you can sponsor me to support my open source work :blush:
License
This repository is licensed under the MIT License.
Copyright © 2017-2022, Josantonius