Last updated: February 16th, 2021

The PdoHelper class is a wrapper for PHP's PDO class that adds several pieces of functionality:

  • Better error logging
  • Query logging/meta information
  • Better connected/disconnected display
  • Stored queries

The logging/meta information improvements are in place just by using the PdoHelper class. In order to view them you can use the following methods:

public PdoDrivers getDriver() Returns the currently configured PDO driver public PdoError[] getErrors() Returns all previous PDOExceptions with their triggering queries public PdoQuery[] getQueries() Returns all queries that have been run through the helper public integer getQueryCount() Returns the number of queries that have been run through the helper

Stored Queries

Stored queries are a way to re-use queries (per database engine) without any extra code. As a quick example, let's create some for both MySQL and MSSQL:

using Stoic\Pdo\PdoDrivers;
using Stoic\Pdo\PdoHelper;

	"SELECT [Email] FROM [dbo].[User] WHERE [ID] = :id",
	[':id' => \PDO::PARAM_INT]);
	"SELECT `Email` FROM `User` WHERE `ID` = :id",
	[':id' => \PDO::PARAM_INT]);

$db = new PdoHelper('mysql:dbname=testdb;host=');
$stmt = $db->prepareStored('sel-user-email', [':id' => 1]); // calls up the MySQL version
$stmt->execute();                                           // because of the connection's driver

Next Up

Continue to read about the web component, or visit the Table of Contents.