Download the PHP package v-dem/queasy-db without Composer
On this page you can find all versions of the php package v-dem/queasy-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download v-dem/queasy-db
More information about v-dem/queasy-db
Files in v-dem/queasy-db
Package queasy-db
Short Description Database access classes, part of QuEasy PHP framework
License LGPL-3.0-only
Homepage https://github.com/v-dem/queasy-db/
Informations about the package queasy-db
QuEasy PHP Framework - Database
Package v-dem/queasy-db
QuEasy DB is a set of database access classes for CRUD operations.
Some of the most usual queries can be built automatically (like SELECT
by unique field value/values, UPDATE
, INSERT
and DELETE
).
More complex queries can be defined in database and/or tables config.
The main goal is to separate SQL
queries out of PHP
code and provide an easy way for CRUD operations.
Features
- QuEasy DB extends
PDO
class, so any project which usesPDO
can be seamlessly moved to use QuEasy DB. - Simple CRUD database operations in just one PHP code row.
- Separating SQL queries from PHP code.
Requirements
- PHP version 5.3 or higher
Installation
composer require v-dem/queasy-db
It will also install v-dem/queasy-helper
.
Usage
Notes
- You can use
setLogger()
method which acceptsPsr\Log\LoggerInterface
implementation to log all queries, by defaultPsr\Log\NullLogger
is used. - By default error mode is set to
PDO::ERRMODE_EXCEPTION
(as in PHP8) if another mode is not set in$options
.
IMPORTANT!
- For MySQL Server need to set option
PDO::MYSQL_ATTR_INIT_COMMAND
toSET GLOBAL SQL_MODE=ANSI_QUOTES
or run same query before calling DB-specific methods. - For MSSQL Server need to run
SET QUOTED_IDENTIFIER ON
orSET ANSI_DEFAULTS ON
query before calling DB-specific methods.
Initialization
Sample:
Or:
Or PDO-way:
- Fourth argument (
$options
) is optional, will be passed toPDO::prepare()
Get all records from users
table
Using foreach
with users
table
Get single record from users
table by id
key
It's possible to use select()
method to pass PDO options; select()
returns PDOStatement instance:
Get multiple records
Insert a record into users
table using associative array
Insert a record into users
table by fields order
Insert many records into users
table using associative array (it will generate single INSERT
statement)
Insert many records into users
table by order
Inserting many records into users
table with field names denoted separately
Also it's possible to use insert()
method (in the same way as above) when need to pass PDO options; returns last insert id for single insert and number of inserted rows for multiple inserts:
- Second argument (
$options
) is optional, will be passed toPDO::prepare()
Get last insert id (alias of lastInsertId()
method)
Update a record in users
table by id
key
- Third argument (
$options
) is optional, will be passed toPDO::prepare()
Update multiple records
Delete a record in users
table by id
key
Delete multiple records
- Second argument (
$options
) is optional, will be passed toPDO::prepare()
Get count of all records in users
table
Using transactions
- On exception transaction is rolled back and exception re-thrown to outer code.
Run custom query (returns PDOStatement
)
- Third argument (
$options
) is optional, will be passed toPDO::prepare()
Run query predefined in configuration
This feature can help keep code cleaner and place SQL code outside PHP, somewhere in config files.
- Possible values for
returns
option areDb::RETURN_STATEMENT
(default, returnsPDOStatement
instance),Db::RETURN_ONE
,Db::RETURN_ALL
,Db::RETURN_VALUE
Also it is possible to group predefined queries by tables:
Using v-dem/queasy-db
together with v-dem/queasy-config
and v-dem/queasy-log
config.php:
Initializing:
- All queries will be logged with
Psr\Log\LogLevel::DEBUG
level. Also it's possible to use any other logger class compatible with PSR-3.
All versions of queasy-db with dependencies
ext-pdo Version *
psr/log Version 1.0.1
v-dem/queasy-helper Version 1.*