Codeigniter 2.0.3与SQL Server活动记录

时间:2011-10-21 15:12:43

标签: sql-server codeigniter

我正在努力升级我在1.7.2到2.0.3上运行的Codeigniter应用程序,但我无法连接到SQL Server。两个版本都在运行php 5.2.10的同一台服务器上运行,并连接到同一个SQL Server。

这是CI 2.0.3中的错误

Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 260

这是我正在使用的连接字符串,当然可以在1.7.2上使用

$db['reports']['hostname'] = "mysqlserver";
$db['reports']['username'] = "sqluser";
$db['reports']['password'] = "sqlpass";
$db['reports']['database'] = "SQLReportDB";
$db['reports']['dbdriver'] = "mssql";
$db['reports']['dbprefix'] = "";
$db['reports']['pconnect'] = TRUE;
$db['reports']['db_debug'] = TRUE;
$db['reports']['cache_on'] = FALSE;
$db['reports']['cachedir'] = "";
$db['reports']['port']     = 972;

在控制器中,我用这个

调用连接
$report_db = $this->load->database('reports', TRUE);

以下是报告失败的加载程序文件中的函数。 第260行是return DB($params, $active_record);

/**
 * Database Loader
 *
 * @param   string  the DB credentials
 * @param   bool    whether to return the DB object
 * @param   bool    whether to enable active record (this allows us to override the config setting)
 * @return  object
 */
public function database($params = '', $return = FALSE, $active_record = NULL)
{
    // Grab the super object
    $CI =& get_instance();

    // Do we even need to load the database class?
    if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
    {
        return FALSE;
    }

    require_once(BASEPATH.'database/DB.php');

    if ($return === TRUE)
    {
        return DB($params, $active_record);
    }

    // Initialize the db variable.  Needed to prevent
    // reference errors with some configurations
    $CI->db = '';

    // Load the DB class
    $CI->db =& DB($params, $active_record);
}

2 个答案:

答案 0 :(得分:0)

以下是我在连接到未列出的SQL Server时使用的一些设置。由于升级可能需要......

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

答案 1 :(得分:0)

$ db ['reports'] ['port']不再有效

需要将端口添加到服务器的末尾

$ db ['reports'] ['hostname'] =“mysqlserver:972”;