PHP code example of adilab / quick-pdo
1. Go to this page and download the library: Download adilab/quick-pdo library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adilab / quick-pdo example snippets
/**
* 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' => '********',
),
);
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));