本文整理匯總了PHP中core\Database::setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:PHP Database::setAttribute方法的具體用法?PHP Database::setAttribute怎麽用?PHP Database::setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core\Database
的用法示例。
在下文中一共展示了Database::setAttribute方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get
/**
* Static method get
*
* @param array $group
* @return \helpers\database
*/
public static function get($group = null)
{
// Determining if exists or it's not empty, then use default group defined in config
$group = !$group ? array('type' => DB_TYPE, 'host' => DB_HOST, 'name' => DB_NAME, 'user' => DB_USER, 'pass' => DB_PASS, 'port' => DB_PORT) : $group;
// Group information
$type = $group['type'];
$host = $group['host'];
$name = $group['name'];
$user = $group['user'];
$pass = $group['pass'];
$port = $group['port'];
// ID for database based on the group information
$id = "{$type}.{$host}.{$port}.{$name}.{$user}.{$pass}";
// Checking if the same
if (isset(self::$instances[$id])) {
return self::$instances[$id];
}
try {
// I've run into problem where
// SET NAMES "UTF8" not working on some hostings.
// Specifiying charset in DSN fixes the charset problem perfectly!
$instance = new Database("{$type}:host={$host};port={$port};dbname={$name};charset=utf8", $user, $pass);
$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Setting Database into $instances to avoid duplication
self::$instances[$id] = $instance;
return $instance;
} catch (PDOException $e) {
//in the event of an error record the error to ErrorLog.html
Logger::newMessage($e);
Logger::customErrorMsg();
}
}