Codeigniter 2.0.3 与 SQL Server Active Record

发布于 2024-12-11 03:32:46 字数 1900 浏览 0 评论 0原文

我正在努力将在 1.7.2 上运行的 Codeigniter 应用程序升级到 2.0.3 但我无法连接到 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);
}

I'm working on upgrading a Codeigniter app I have running on 1.7.2 to 2.0.3 but I'm not able to connect to SQL Server . Both versions are running on the same server running php 5.2.10 and connecting to the same SQL Server.

This is the error from CI 2.0.3

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

This is the connection string I'm using which of course works on 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;

In the controller I call the connection with this

$report_db = $this->load->database('reports', TRUE);

Below is the function in the loader file where it reports the failure.
Line 260 is 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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伏妖词 2024-12-18 03:32:46

以下是我在连接到您未列出的 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;

Here are some settings I use in connecting to a SQL Server you haven't listed. Might be required due to upgrade...

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
终难遇 2024-12-18 03:32:46

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

需要在服务器末尾添加端口

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

$db['reports']['port'] is no longer valid

The port needs to be added to the end of the server

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文