Database Connection Library

2.0.1 2015-11-30 22:49 UTC

This package is auto-updated.

Last update: 2024-12-20 22:06:04 UTC


README

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