选择语言 :

 Driver_Database_Driver_MySQLI::_select_db

切换表

void Driver_Database_Driver_MySQLI::_select_db( string $database )

参数列表

参数 类型 描述 默认值
$database string Database
返回值
  • void
File: ./drivers/database/mysqli/mysqli.class.php
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
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;
    }
}