Codeigniter 2.0.3 与 SQL Server Active Record
我正在努力将在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我在连接到您未列出的 SQL Server 时使用的一些设置。可能是因为升级需要...
Here are some settings I use in connecting to a SQL Server you haven't listed. Might be required due to upgrade...
$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";