A simple database abstraction for using PDO with MySQL, Postgres, and SQLite.

Installs: 295

Dependents: 0

Suggesters: 0

Stars: 58

Watchers: 7

Forks: 29

Open Issues: 3

1.0.0 2013-04-27 08:01 UTC


A simple database client utilizing PHP PDO.


  • Maintains at most one connection to slave DB and one to master DB per request.
  • Automatically uses slave connection for data retrieval, master for writes.
  • Randomized slave connection, with automatic fallback to master if no slaves exist.
  • Enforces data sanitization (using PDO prepared statements and bind parameters).
  • Catches all errors, and writes them to error log if configured to do so.
  • Automatic timestamps for creates and updates
  • Handles multiple inserts with a single query.
  • Fallback to custom queries if one needs to do a join or second order query.
  • Deals exclusively with associative arrays for input/output



    'my_database_port' // optional

Slaves (optional)

    'my_database_port' // optional

    'my_database_port' // optional
  // etc



  $results = PDOWrapper::instance()->select('post', array('thread_id'=>$thread_id));
  $results = PDOWrapper::instance()->select('thread', array('open'=>0), $limit+1, $start, array('favs'=>'DESC'));


  $invite_id = PDOWrapper::instance()->insert('invite', array(
    'user_id' => $user_id,
    'text' => $text,
    'invite_key' => $invite_key

Complex Queries with bind parameters

  $post = PDOWrapper::instance()->queryFirst('
    SELECT invite.*, user.name FROM invite
    LEFT JOIN user ON user.id=invite.user_id
    WHERE invite_key=:invite_key
  ', array(':invite_key'=>$invite_key));