Download the PHP package tivins/database without Composer
On this page you can find all versions of the php package tivins/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
A PDO Wrapper
A Secure, fluent, lightweight, and efficient PDO wrapper.
Help to protect again SQL injections.
Install
Requirements
See composer.json.
Install with composer
Quick example
Summary
- Usage
- Connectors
- Queries :
- Select
- Insert
- Update
- Create
- Delete
- Extended
- SelectInsert
- Merge
- Conditions and expressions
- Nested conditions
- Expressions
- Predefined expressions
- insert expression
- Having
- Transversal
- Order by
- Range/Limit
- Transactions
- Error handling
- Development * [Unit tests](#unit-tests)
Usage
Connectors
Creating a Connector
instance.
or
Then create an instance of Database, with the created connector :
A ConnectionException
can be thrown when the new Database()
attempt to connect the given Connector.
Using queries
Both usages below are valid :
Select query
Basic
Join
use as well innerJoin
, leftJoin
.
Expression
Group by
Condition Expression
Range/Limit
Order by
orderBy()
add a new order statement in the query. It can be called multiple times.
Multiple times. In the following example, the results will be sorted by post_type
, and then, by date
:
Insert query
Multiples inserts
or,
execute()
will insert two rows in the table book
.
See the build result
* Query * ParametersInsert expressions
Expressions can be used inside the array given to fields()
function.
Execute() will insert two rows in the table book
.
See the build result
* Query * ParametersInsertExpression are also allowed with a MergeQuery.
Update query
Merge query
Delete query
Perform a delete
query on the given table.
All methods of DeleteQuery
object.
Create query
Perform a create table
query on the current database.
Field types :
-
Integers
-
UnitEnum or BackedEnum
- Standard Enum
Select-Insert Query
Perform a select, then an insert if not found.
By default, array given in matching()
are used to insert the new record.
You can define the fields for the insert query:
Expressions
You can use SelectQuery::addExpression()
to add an expression to the selected fields.
Signature : ->addExpression(string $expression, string $alias, array $args)
.
Predefined expressions
Count (addCount()
)
Conditions
Some examples :
Nested conditions
Conditions are available for DeleteQuery
.
And below is equivalent :
Having
Transactions
Full Example
See /tests/FullTest.php
Error handling
There are three main exception thrown by Database.
- ConnectionException, raised by the Database constructor, if a connection cannot be established.
- DatabaseException, thrown when a PDO exception is raised from the query execution.
- ConditionException, raised when a given operator is not allowed.
All of these exceptions has an explicit message (from PDO, essentially).
Usage short example :
Unit tests
Create a test database, and a grant to a user on it.
Add a phpunit.xml
at the root of the repository.
Then, run unit tests :
To include a coverage test, use :
License
Database is released under the MIT License. See the bundled LICENSE file for details.
In addition, if you are using the --dev
mode, some parts of the project have their own licenses attached (either in the source files or in a LICENSE
file next to them).
Stats
All versions of database with dependencies
ext-pdo Version *