连接数据库
$use_connection_type 默认不传为自动判断,可传true/false,若传字符串(只支持a-z0-9的字符串),则可以切换到另外一个连接,比如传other,则可以连接到$this->_connection_other_id所对应的ID的连接
null Driver_Database_Driver_Postgre::connect( [ boolean $use_connection_type = null ] )
参数列表
参数 类型 描述 默认值 $use_connection_type
boolean
是否使用主数据库 null
5354555657585960616263646566676869707172737475767778798081public
function
connect(
$use_connection_type
= null)
{
if
(null!==
$use_connection_type
)
{
$this
->_set_connection_type(
$use_connection_type
);
}
$connection_id
=
$this
->connection_id();
# 最后检查连接时间
static
$last_check_connect_time
= 0;
if
(!
$connection_id
|| !isset(Database_Driver_Postgre::
$_connection_instance
[
$connection_id
]))
{
$this
->_connect();
}
# 如果有当前连接,检查连接
if
(
$last_check_connect_time
>0 && time()-
$last_check_connect_time
>=5)
{
# 5秒后检查一次连接状态
$this
->_check_connect();
}
# 设置编码
$this
->set_charset(
$this
->config[
'charset'
]);
$last_check_connect_time
= time();
}