Skip to content

Instantly share code, notes, and snippets.

@chrisoverstreet
Last active August 17, 2020 18:25
Show Gist options
  • Save chrisoverstreet/5d59fe7833fe65454005e3cee613dd8f to your computer and use it in GitHub Desktop.
Save chrisoverstreet/5d59fe7833fe65454005e3cee613dd8f to your computer and use it in GitHub Desktop.
class DbHandler
{
private $conn;
private $pdo;
/**
* DbHandler constructor.
* Pass in connections to prevent race conditions being cause by multiple connections being created
* @param {mysqli} $dbConnection - optional mysqli connection
* @param {PDO} $pdoConnection - optional pdo connection
*/
function __construct($dbConnection = null, $pdoConnection = null)
{
/**
* @var DbConnect
*/
$db = new DbConnect();
/**
* @var mysqli
*/
$this->conn = $dbConnection ? $dbConnection : $db->connect();
/**
* @var PDO
*/
$this->pdo = $pdoConnection ? $pdoConnection : $db->getPdoConnection();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment