选择语言 :

 Driver_Database_Driver_MySQL::_select_db

切换表

void Driver_Database_Driver_MySQL::_select_db( string $database )

参数列表

参数 类型 描述 默认值
$database string Database
返回值
  • void
File: ./drivers/database/mysql/mysql.class.php
protected function _select_db($database)
{
    if (!$database)return;

    $connection_id = $this->connection_id();

    if (!$connection_id || !isset(Database_Driver_MySQL::$_current_databases[$connection_id]) || $database!=Database_Driver_MySQL::$_current_databases[$connection_id])
    {
        $connection = Database_Driver_MySQL::$_connection_instance[$connection_id];

        if (!$connection)
        {
            $this->connect();
            $this->_select_db($database);
            return;
        }

        if (!mysql_select_db($database, $connection))
        {
            throw new Exception('选择数据表错误:' . mysql_error($connection) . mysql_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_MySQL::$_current_databases[$connection_id] = $database;
    }
}