aalfiann/lazypdo

A PHP class to make lazy load PDO connection to database.

1.0.1 2019-04-30 17:08 UTC

This package is auto-updated.

Last update: 2024-10-29 05:59:17 UTC


README

Latest Stable Version Total Downloads License

A PHP class to make lazy load PDO connection to database.
You can use LazyPDO to replace the default PDO, when you need to lazy load. No database connection will be made until first call to one of PDO's methods.

Installation

Install this package via Composer.

composer install aalfiann/lazypdo

Usage

require 'vendor/autoload.php';
use aalfiann\LazyPDO;

$dsn = 'mysql:hostname=localhost;dbname=test';
$user = 'test';
$password = 'test';

$pdo = new LazyPDO($dns, $user, $password); // doesn't connect yet

$pdo->query('SELECT * FROM `table` WHERE 1'); // connection is made before executing query