PHP
Latest commit 9b4ec07 Feb 16, 2017 @g105b g105b Smaller logo
Permalink
Failed to load latest commit information.
bin
src
test/unit
.gitignore
.scrutinizer.yml
LICENSE
README.md
circle.yml
composer.json
composer.lock
logo.png
phpunit.xml

README.md

Database logic organisation for PHP 7 projects.

Database API organisation for PHP 7 projects.

Encloses your application's database scripts within a simple and standardised interface, separating database access from your page logic.

Documentation: https://php.gt/docs/database


Build status Code quality Code coverage Current version

Example usage

This library provides database access via raw SQL or using a PHP Query Builder, both interoperable through the same API.

The API is consistent for all database operations. To execute an example query located at src/query/collectionName/exampleQueryName.sql, the following pattern is used:

$result = $db["collectionName"]->exampleQueryName($parameters)

Examples of CRUD operations:

// "Retrieve" or "get" methods always return a ResultSet.
$shopItems = $db["shop"]->getItemsInCategory("books");

foreach($shopItems as $item) {
    setItemName($item["name"]);
    setItemPrice($item["price"]);
}

// The fields of the first (or only) Row of a ResultSet can be addressed on the
// ResultSet itself:
$customer = $db["customer"]->getById(105);
outputGreeting("Hello, " . $customer["first_name"]);

// "Create" or "insert" methods always return the last inserted ID:
$newCustomerId = $db["customer"]->create([
    "first_name" => "Marissa",
    "last_name" => "Mayer",
    "dob" => new DateTime("1975-05-30"),
]);

// "Update" or "set" methods, as well as "delete" or "remove" methods
// always return the number of affected rows:
$numberOfItemsAffected = $db["item"]->updatePrice([
    "percent" => 12.5
    "max_increase" => 20.00
]);

$numberOfDeletedReviews = $db["review"]->deleteOldReviews([
    "createdAfter" => new DateTime("-6 months"),
]);

Features at a glance

Compatible database engines

Compatibility is provided for the following database providers:

  • MySQL
  • Postgres
  • SQLite
  • SQL Server
  • Mongo (planned)
  • CouchDB (planned)