It allows you to connect the database to a project using a wrapper around the PDO.
- PHP >= 7.0
Run the following command in the root directory of your web project:
composer require aengine/orchid-database
Connect to the server
Db::setup([
[
'dsn' => 'mysql:host=HOST;dbname=DB-NAME',
'username' => 'USERNAME',
'password' => 'PASSWORD',
// 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 = Db::query('SELECT * FROM `user` WHERE `age` > 23');
while ($a = $stm->fetch(PDO::FETCH_ASSOC)) {
// some action
pre($a);
}Select rows
$list = Db::select('SELECT * FROM `products` WHERE `price` >= 150');Select first element of array from Db::select
$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');Please see CONTRIBUTING for details.
The Orchid Database is licensed under the MIT license. See License File for more information.