[英]Codeigniter: How to setup connection to a SQL server (2008)
I've spent many days on this task, and I can't see the end until now. 我已经在这项任务上花了很多天,但直到现在我都看不到结局。 In the past day I managed to install sqlsrv driver on my PHP environment successfully but now when I try to connect I get this message:
在过去的一天里,我设法在PHP环境中成功安装了sqlsrv驱动程序,但是现在当我尝试连接时,我收到以下消息:
Unable to connect to your database server using the provided settings.
无法使用提供的设置连接到数据库服务器。
My settings in application/config/database.php
are so defined: 我在
application/config/database.php
中的设置是这样定义的:
$db['dbname']['hostname'] = "ENJ01\SQLEXPRESS";
$db['dbname']['username'] = "user";
$db['dbname']['password'] = "password";
$db['dbname']['database'] = "dbname";
$db['dbname']['dbdriver'] = "sqlsrv";
$db['dbname']['dbprefix'] = "";
$db['dbname']['pconnect'] = TRUE;
$db['dbname']['db_debug'] = TRUE;
$db['dbname']['cache_on'] = FALSE;
$db['dbname']['cachedir'] = "";
$db['dbname']['char_set'] = "utf8";
$db['dbname']['dbcollat'] = "utf8_general_ci";
$db['dbname']['swap_pre'] = '';
$db['dbname']['autoinit'] = TRUE;
$db['dbname']['stricton'] = FALSE;
something wrong? 有问题?
Here my environment configuration: 这是我的环境配置:
I've had the same trouble you've had about a year ago. 我遇到了大约一年前的同样麻烦。 Have a look at the replies here, there are some great suggestions from people in there: CodeIgniter MSSQL connection
看看这里的答复,那里的人有一些很棒的建议: CodeIgniter MSSQL连接
Also, a thread was posted a few days ago here: CI connect to SQL SERVER - check out my answer over there as well, since it's solved the problem for that particular developer. 另外,几天前在这里发布了一个主题: CI连接到SQL SERVER-也可以在那查看我的答案,因为它已经解决了该特定开发人员的问题。
I would've wrote a comment, but I haven't the required reputation yet. 我会写评论,但是我还没有必需的声誉。 Anyways...
无论如何...
I noticed your hostname 'ENJ01\\SQLEXPRESS', have you tried using 'localhost' instead? 我注意到您的主机名“ ENJ01 \\ SQLEXPRESS”,您是否尝试过使用“本地主机”?
Also, try setting the port to 1433, with $db['dbname']['port'] = 1433; 另外,尝试将端口设置为1433,其中$ db ['dbname'] ['port'] = 1433;
I had the same problem solved by setting 我通过设置解决了相同的问题
$ db ['default'] ['pconnect'] = FALSE; $ db ['default'] ['pconnect'] = FALSE;
Make 1. $db['default']['pconnect'] = FALSE;
使1.
$db['default']['pconnect'] = FALSE;
. 。 Then go to
system/database/drivers/sqlsrv/sqlsrv_driver.php
然后转到
system/database/drivers/sqlsrv/sqlsrv_driver.php
function db_pconnect()
{
//$this->db_connect(TRUE);
return $this->db_connect(TRUE);
}
and 和
function affected_rows()
{
//return @sqlrv_rows_affected($this->conn_id);
return @sqlsrv_num_rows($this->result_id);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.