Codeigniter: How to setup connection to a SQL server (2008)

ぃ、小莉子 提交于 2019-12-17 17:14:57

问题


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:

Unable to connect to your database server using the provided settings.

My settings in application/config/database.php are so defined:

$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:

  • wampserver 2.4 x86
  • PHP 5.4.16
  • sqlsrv driver -> php_sqlsrv_54_ts.dll
  • Codeigniter 2.1.4

回答1:


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

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.




回答2:


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?

Also, try setting the port to 1433, with $db['dbname']['port'] = 1433;




回答3:


I had the same problem solved by setting

$ db ['default'] ['pconnect'] = FALSE;




回答4:


Make 1. $db['default']['pconnect'] = FALSE;. Then go to 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);
}


来源:https://stackoverflow.com/questions/19431447/codeigniter-how-to-setup-connection-to-a-sql-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!