Dsn.class.php
881 Bytes
<?php
/**
*
*
*/
class Util_Dao_Dsn
{
/**
* 获取数据库
*
* @param String $dbname 数据库名称
* @param String $readtag 读、写
* @return Array
**/
public static function getDbServer($dbname, $readtag = true, $dbType = 'Mysql',$charset='UTF8MB4')
{
$options = array(
'dbname' => 'pre_'.$dbname,
'readtag' => $readtag
);
$server = Util_Server::factory('Db', $dbType, $options)->loadBalanceServer();
if (empty($server))
{
throw new Util_Dao_Exception('server config is null ,find: ' . $dbname . ' No such config file ');
}
$driver_options = array(
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES '.$charset,
PDO::ATTR_PERSISTENT => false,
PDO::ATTR_TIMEOUT => defined('Util_DB_ATTR_TIMEOUT') ? Util_DB_ATTR_TIMEOUT : 30
));
return array_merge($server, $driver_options);
}
}