Zend_DB でPDO接続

投稿者:

/* Configures PDO to execute the ‘SET NAMES UTF8;’ SQL query just before
any other query. If no query is executed on your page, this will not be
executed. */
$pdoParams = array(PDO::MYSQL_ATTR_INIT_COMMAND => ‘SET NAMES UTF8;’);
$params = array(
‘host’ => ‘localhost’,
‘username’ => ‘username’,
‘password’ => ‘password’,
‘dbname’ => ‘dbname’,
‘driver_options’ => $pdoParams
);
try {
$db = Zend_Db::factory(‘PDO_MYSQL’, $params);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
} catch (Exception $e) {
exit($e->getMessage());
}
Zend_Registry::set(‘dbAdapter’, $db);

Thank you for reading this post, don't forget to subscribe!