Skip to content
GrumpyCrouton edited this page Oct 19, 2022 · 10 revisions

GrumpyPDO

GrumpyPDO is an extension of PDO, so any regular PDO methods also work with GrumpyPDO. This means you can switch from regular PDO to GrumpyPDO at any time and it won't break your existing code.

Set Up GrumpyPDO

Composer

  • GrumpyPDO has Composer support! The composer package is grumpycrouton/grumpypdo

Manual

  • Copy grumpypdo.php into your server, then include it in your page and initialize it as a variable.
include "grumpypdo.php";
$db = new GrumpyPDO("localhost", "username", "password", "database");

Default Attributes

protected $default_attributes = array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES => false,
);

If you want to add more attributes, or alter existing ones, pass an array of attributes as a key->value pair as the 5th parameter of the class initialization.

Whatever you pass will be added to, or overwrite, the existing attributes.

Initialization Signature

__construct($hostname, $username, $password, $database, $attributes = array(), $dsn_prefix = "mysql", $dsn_param_string = "")