Skip to content

Instantly share code, notes, and snippets.

@gundamew
Last active January 19, 2021 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gundamew/3f276c6cf753220e4ae91dc4b4e5091e to your computer and use it in GitHub Desktop.
Save gundamew/3f276c6cf753220e4ae91dc4b4e5091e to your computer and use it in GitHub Desktop.
PDO with options.
<?php
function getPDOInstance($host, $name, $user, $password)
{
$dsn = str_replace(
['{HOST}', '{NAME}'],
[$host, $name],
'mysql:host={HOST};dbname={NAME};charset=utf8mb4'
);
$options = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
];
return new \PDO($dsn, $user, $password, $options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment