Update database.php

This commit is contained in:
Namhyeon Go 2018-04-29 00:58:22 +09:00 committed by GitHub
parent 34e779ace9
commit bb11f2d9a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,17 +10,21 @@ if(!function_exists("get_db_connect")) {
function get_db_connect() { function get_db_connect() {
$config = get_config(); $config = get_config();
$conn = new PDO( try {
sprintf( $conn = new PDO(
"mysql:host=%s;dbname=%s;charset=utf8", sprintf(
$config['db_host'], "mysql:host=%s;dbname=%s;charset=utf8",
$config['db_name'] $config['db_host'],
), $config['db_name']
$config['db_username'], ),
$config['db_password'], $config['db_username'],
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") $config['db_password'],
); array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
$conn->query("SET NAMES 'utf8'"); );
$conn->query("SET NAMES 'utf8'");
} catch(Exception $e) {
set_error($e->getMessage());
}
return $conn; return $conn;
} }