Created
October 16, 2012 13:44
-
-
Save fomigo/3899376 to your computer and use it in GitHub Desktop.
PDO connection - some useful options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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