Last active
December 14, 2015 04:49
-
-
Save tiomoreno/5030656 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Cria uma instância da classe PDO, setando o modo de erro para gerar exceções | |
* | |
*/ | |
class PdoFactory { | |
public function __construct() { | |
} | |
public static function getInstance(array $params) { | |
try { | |
$pdoObject = new PDO($params['dsn'], $params['user'], $params['password']); | |
// modifica o modo de erro. | |
$pdoObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
// habilita o uso de queries com buffer (MySQL somente!) | |
$pdoObject->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); | |
return $pdoObject; | |
} catch (PDOException $e) { | |
echo $e->getMessage(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment