Database Connection Library.
Efficiently manages a connection, preventing a new one from being established if a matching connection already exists.
Install via composer:
composer require minphp/db:dev-master
use Minphp\Db\PdoConnection;
$dbInfo = array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'databasename',
'user' => 'user',
'pass' => 'pass'
);
$connection = new PdoConnection($dbInfo);
$connection->query('SELECT * FROM table WHERE id=?', 1);
By default, PdoConnection will only connect to the database when a connection is required. To explicitly connect to the database use connect()
:
use Minphp\Db\PdoConnection;
$dbInfo = array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'databasename',
'user' => 'user',
'pass' => 'pass'
);
$connection = new PdoConnection($dbInfo);
$connection->connect();
// Connection now ready and waiting