Download the PHP package liftkit/database without Composer
On this page you can find all versions of the php package liftkit/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download liftkit/database
More information about liftkit/database
Files in liftkit/database
Package database
Short Description Database library for LiftKit
License LGPL-2.1-only
Informations about the package database
LiftKit database library
Installation
Let's jump right in to some examples.
Connection
Establish a connection
Run a raw SQL query
Using placeholders
Result objects
Loop through results
Fetch a single column as an array
Fetch all rows as an array of entities
Fetch all rows as an array of associative arrays
Query builder
New query
Simple select query
More complicated select query
Note that the method $connection->quoteIdentifier()
is called on the right parameters.
That's because the right parameter is expected to be a value. If it is instead
a SQL identifier, it must be quoted.
This example shows the query with MySQL style identifier quotes to illustrate the point.
Note the difference between the JOIN
conditions and the WHERE
conditions.
Update query
Note that update queries can utilize conditions the same as select statements.
Insert query
Insert queries return their insert ID.
Delete query
Note that delete queries can use conditions the same as select queries.
Subqueries
Subqueries can be substituted pretty much anywhere a value or identifier can be.
Note: This is also an example of how to use raw SQL instead of escaped values in your queries
using the method $connection->createRaw()
. Select arguments, like the left had side of conditions,
will be quoted as an identifier unless otherwise specified.
Composing parts of queries
This comes in hand for extracting away parts of queries you use often, while retaining the ability to combine them with other queries.
Let's say you have a function that returns all of the rows from tbl
.
Now you need another query which select only records which are active from tbl
. Notice the additions to getAllTblRows
.
Table objects
Table objects are meant to reduce the boilerplate you need to place in your query builder queries.
Fetching multiple rows
Fetching multiple rows with composed query
Fetching a single row
Inserting a new row
`
Updating a row
NOTE: The library will auto-detect the primary key column and create an equal condition on that column.
Deleting a row
More info on table objects, relations, and entities coming soon!
All versions of database with dependencies
liftkit/collection Version ^1.0
ext-pdo Version *
ext-json Version *