adilab / quick-pdo
Adi PDO handler
v1.0.3
2016-03-12 12:49 UTC
This package is not auto-updated.
Last update: 2024-12-13 20:10:30 UTC
README
Allows to work with PDO faster and more convenient way.
Features
- Aid for work with multi database,
- Quick configuration,
- Aid for work with SQL parameters,
- Aid for INSERT and UPDATE statements,
- Quick access to metadata from the schema.
Installing
Preferred way to install is with Composer.
Install this library using composer:
$ composer require adilab/quick-pdo
Configuration:
/** * config/adi/databases.php */ return array( 'db1' => array( 'dsn' => 'mysql:host=127.0.0.1;dbname=db1;charset=utf8', 'user' => 'db1', 'pass' => '********', ), 'db2' => array( 'dsn' => 'pgsql:host=127.0.0.1;dbname=db2', 'user' => 'db2', 'pass' => '********', ), );
Usage:
require('vendor/autoload.php'); use Adi\QuickPDO\DB; // Usage fetch() method foreach (DB::main()->fetch('SELECT * FROM my_table WHERE my_column > ?', 10) as $row) { var_dump($row); } // Usage row() method var_dump(DB::alias('db2')->row("SELECT * FROM my_table WHERE my_column = ?", 2)); // Usage value() method if (DB::alias('db1')->value("SELECT count(*) > 1 FROM my_table")) { echo 'There are many records.'; } // Usage insert() method $id_key = DB::main()->insert('my_table', array('my_column1' => 'a', 'my_column2' => 'b')); echo $id_key; // Usage update() method DB::main()->update('my_table', array('my_column1' => 'a', 'my_column2' => 'b'), new Where('id > ? AND id < ? OR id = ?', array(10,20,30))); DB::main()->update('my_table', array('my_column1' => 'a', 'my_column2' => 'b'), array('id' => 25));