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.
Helps protect against SQL injections.
Install
Requirements
- PHP >= 8.1
- PDO extension
- Optional development dependencies:
See composer.json.
Installation with Composer
Quick example
Table of Contents
- Usage
- Connectors
- Queries
- Select
- Insert
- Update
- Create
- Delete
- Extended Queries
- SelectInsert
- Merge
- Conditions and Expressions
- Nested conditions
- Expressions
- Predefined expressions
- Insert expressions
- Having
- Common Operations
- Order by
- Range/Limit
- Transactions
- Error handling
- Development
- Unit tests
Usage
Connectors
Creating a Connector instance.
Or
Then create a Database instance with the created connector:
A ConnectionException can be thrown when the new Database() constructor attempts to connect using the given Connector.
Using Queries
Both approaches below are valid:
Select Query
Basic Usage
Joins
You can also use innerJoin and leftJoin.
Expressions
Group By
Condition Expressions
Range/Limit
Order By
orderBy() adds a new order statement to the query. It can be called multiple times.
Multiple times. In the following example, the results will be sorted by post_type, then by date:
Insert Query
Multiple inserts
Or,
execute() will insert two rows into the book table.
See the build result
* Query * ParametersInsert expressions
Expressions can be used inside the array passed to the fields() method.
execute() will insert one row into the geom table.
See the build result
* Query * ParametersInsertExpression is also allowed with a MergeQuery.
Update Query
Merge Query
Delete Query
Performs a DELETE query on the given table.
All methods from DeleteQuery object.
Create Query
Performs a CREATE TABLE query on the current database.
Field types:
-
Integers
-
UnitEnum or BackedEnum
- Standard Enum
Select-Insert Query
Performs a SELECT, then an INSERT if not found.
By default, the array given in matching() is 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.
The following is equivalent:
Having
Transactions
Full Example
See FullTest.php
Error handling
There are three main exceptions thrown by the Database class:
- ConnectionException - raised by the Database constructor if a connection cannot be established
- DatabaseException - thrown when a PDO exception is raised from query execution
- ConditionException - raised when a given operator is not allowed
All of these exceptions have explicit messages (essentially from PDO).
Short usage example:
Unit Tests
Create a test database and grant permissions to a user on it.
Add a phpunit.xml file at the root of the repository.
Then run the unit tests:
To include coverage testing, use:
License
This project 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).
Statistics
All versions of database with dependencies
ext-pdo Version *