protected
function
_select_db(
$database
)
{
if
(!
$database
)
return
;
$connection_id
=
$this
->connection_id();
if
(!
$connection_id
|| !isset(Database_Driver_MySQLI::
$_current_databases
[
$connection_id
]) ||
$database
!=Database_Driver_MySQLI::
$_current_databases
[
$connection_id
])
{
$connection
= Database_Driver_MySQLI::
$_connection_instance
[
$connection_id
];
if
(!
$connection
)
{
$this
->connect();
$this
->_select_db(
$database
);
return
;
}
if
(!mysqli_select_db(
$connection
,
$database
))
{
throw
new
Exception(
'选择数据表错误:'
. mysqli_error(
$connection
), mysqli_errno(
$connection
));
}
if
(IS_DEBUG)
{
$host
=
$this
->_get_hostname_by_connection_hash(
$this
->connection_id());
$benchmark
= Core::debug()->info((
$host
[
'username'
]?
$host
[
'username'
].
'@'
:
''
) .
$host
[
'hostname'
] . (
$host
[
'port'
] &&
$host
[
'port'
]!=
'3306'
?
':'
.
$host
[
'port'
]:
''
).
'select to db:'
.
$database
);
}
# 记录当前已选中的数据库
Database_Driver_MySQLI::
$_current_databases
[
$connection_id
] =
$database
;
}
}