Skip to content

A simple PDO Wrapper and Query Builder made to shorten the time it takes to get results from basic SQL queries.

Notifications You must be signed in to change notification settings

TomWright/ExtendedPDO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extended PDO

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.

About

A simple PDO Wrapper and Query Builder made to shorten the time it takes to get results from basic SQL queries.

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages