Skip to content

Instantly share code, notes, and snippets.

@fomigo
Created October 16, 2012 13:44
Show Gist options
  • Save fomigo/3899376 to your computer and use it in GitHub Desktop.
Save fomigo/3899376 to your computer and use it in GitHub Desktop.
PDO connection - some useful options
<?php
try {
$pdo = new PDO(
'mysql:host=localhost;dbname=test_database',
'username',
'password',
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
PDO::ATTR_PERSISTENT => true, // BEST OPTION
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
)
);
// $pdo = new PDO('mysql:host=localhost;dbname=test_jokes', 'root', 'gfhjkmm');
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $pdo->exec('SET NAMES "utf8"');
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment