Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.

AEngine/database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AEngine Database

It allows you connect the database to a project using a wrapper around the PDO.

Requirements

  • PHP >= 7.0

Installation

Run the following command in the root directory of your web project:

composer require aengine/database

Usage

AEngine\Database\Db::initialize([
    [
        'dsn' => 'mysql:host=HOST;dbname=DB_NAME',
        'username' => 'DB_USER',
        'password' => 'DB_PASS',
        // additional can be passed options, server-role and pool name:
        // 'option'     => [
        //     PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
        //     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        // ],
        // 'role'       => 'master', // or slave
        // 'pool_name'  => 'default', // pool list of connections
    ],
    // possible another connection config
    // for the implementation of master-slave
]);

Query execution

$stm = AEngine\Database\Db::query('SELECT * FROM `user` WHERE `age` > 23');

while ($a = $stm->fetch(PDO::FETCH_ASSOC)) {
    // some action
    var_dump($a);
}

Aliases

Select rows

$list = $db->select('SELECT * FROM `products` WHERE `price` >= 150');

Select first element of array from select method

$first = $db->selectOne('SELECT * FROM `products` WHERE `price` >= 150');

Affect row and return count of affected

$affected = $db->affect('INSERT INTO `products` SET `name` = "Socks with owls", `price` = 200');

Contributing

Please see CONTRIBUTING for details.

License

The AEngine Database is licensed under the MIT license. See License File for more information.

About

Database is PDO wrapper

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages