Download the PHP package ifcanduela/db without Composer
On this page you can find all versions of the php package ifcanduela/db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package db
db: Query Builder and Connection manager
An easy-to-use database connection manager and query builder for SQLite and MySQL.
Getting started
Install using Composer.
Connecting to a database
The ifcanduela\db\Database class extends PDO, but includes two static methods to connect
to MySQL and SQLite:
The arguments match those in the PDO constructor.
The following options are set by default when using the static factories to create a connection:
- PDO will throw exceptions on error.
- Results will be returned as associative arrays.
- Prepared statements will not be emulated.
Create a connection using an array
Connections can also be created using an array:
Query builder
You can get the parameters for the prepared statement by calling getParams() on the $query
object.
Running queries
When you have a connection and have built a query, you can call the run method on the connection
to run a query:
Which is equivalent to this:
Logging queries
Queries run through the run() method can be logged using an object implementing LoggerInterface.
The query log entries use the Logger::INFO level. For example, using Monolog:
Query builder API
Select queries
There is also a Query::count() method that will select a COUNT(*) column
automatically.
Insert queries
Update queries
Delete queries
Specifying conditions
Building conditions is accomplished by using the where(), andWhere() and orWhere()
methods (or their grouping equivalents, having(), andHaving() and orHaving()).
Conditions must be associative arrays, where keys are expected to be the column names
in the comparison and the left-side value are values or indexed arrays of operator and
value.
Values will be converted to prepared statement parameters unless you use the
ifcanduela\db\qi() function on them.
An example of a select query with multiple conditions would be this:
The resulting SQL will be similar to the following snippet:
And the parameters array would look like this:
Complex conditions
If using the where() methods is confusing or insufficient, you can use simple arrays
to specify nested conditions:
Which will result in something like this:
License
MIT.
All versions of db with dependencies
ext-pdo Version *
ext-json Version *