tomwright/extended-pdo

There is no license information available for the latest version (1.0.2) of this package.

An extension on the standard PDO library.

1.0.2 2017-05-22 14:52 UTC

README

Build Status Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License

Installation

composer install tomwright/extended-pdo

Connecting

ExtendedPDO implements the singleton design pattern using tomwright/singleton. For more information on how the following code works, see the documentation.

$db = ExtendedPDO::createConnection($dsn, $username, $password, 'my-main-db');
$db2 = ExtendedPDO::getInstance('my-main-db');

var_dump($db === $db2) // TRUE

Usage

// Returns an array of records
$db->queryAll('SELECT * FROM users WHERE username = :username', [':username' => 'Tom']);

// Returns the first record
$db->queryRow('SELECT * FROM users WHERE username = :username LIMIT 1', [':username' => 'Tom']);

Query Return Types

You can set the return type of the dbQuery(), queryAll() and queryRow() methods using $db->setReturnType($x) where $x is the return type you'd like to use.

Available return types are as follows:

  • ExtendedPDO::RETURN_TYPE_OBJECT - Your results will be returned as objects
  • ExtendedPDO::RETURN_TYPE_ASSOC - Your results will be returned as associative arrays
  • ExtendedPDO::RETURN_TYPE_STMT - The statement object will be returned directly

You can also set a return type of \PDO::FETCH_ASSOC for example and it will override any of the above. This makes all of the standard PDO fetch types usable.

Query Builder

ExtendedPDO also comes with it's own Query Builder.