Skip to content

phillipsdata/minphp-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minphp/Db

Build Status Coverage Status

Database Connection Library.

Efficiently manages a connection, preventing a new one from being established if a matching connection already exists.

Installation

Install via composer:

composer require minphp/db:dev-master

Basic Usage

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);

Explicitly Connecting

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