1. Go to this page and download the library: Download devman87/simple-pdo-wrapper 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/ */
use SimplePdoWrapper\DB;
// Indicate this only 1 time, at the beginning of the application
DB::setConfig('your-config.php');
DB::connection(); // connection default, you can explicitly specify. Example: DB::connection('config1') or DB::connection('config2');
// sql requests
DB::request('SELECT * FROM table WHERE id = ?', [$id])->fetchAll();
DB::request('INSERT INTO table (column1, column2) VALUES (?, ?)', ['John', 'Doe']);
try {
DB::beginTransaction();
if (DB::request('UPDATE table1 SET column = ? WHERE id = ?', [$value1, $id1])->rowCount() < 1) {
return false;
}
if (DB::request('UPDATE table2 SET column = ? WHERE id = ?', [$value2, $id2])->rowCount() < 1) {
return false;
}
DB::commit();
return true;
} catch (\PDOException $e) {
DB::rollBack();
}
$pdo = DB::getPdo();
DB::query('SELECT * FROM table')->fetchAll();
// connect to config1.
DB::connection(); /* or DB::connection('config1'); */
DB::query('SELECT * FROM table')->fetchAll();
// connect to config2. Now all requests will be from config2
DB::connection('config2');
DB::query('SELECT * FROM table')->fetchAll();
/* We return to config1. Now all requests will be from config1. We have already connected to config1, for performance,
the DB class stores all connections in array, so there will not reconnection to config1.*/
DB::connection(); /* or DB::connection('config1'); */
DB::query('SELECT * FROM table')->fetchAll();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.