php Codeigniter:如何设置与 SQL 服务器的连接 (2008)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19431447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:27:01  来源:igfitidea点击:

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

phpsql-serversql-server-2008codeignitersqlsrv

提问by Splact

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.phpare 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:

这里我的环境配置:

  • wampserver 2.4 x86
  • PHP 5.4.16
  • sqlsrv driver -> php_sqlsrv_54_ts.dll
  • Codeigniter 2.1.4
  • wampserver 2.4 x86
  • PHP 5.4.16
  • sqlsrv 驱动程序 -> php_sqlsrv_54_ts.dll
  • 代码点火器 2.1.4

回答by Petre P?tra?c

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 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.

此外,几天前在这里发布了一个线程:CI 连接到 SQL SERVER- 也请查看我的答案,因为它已经解决了该特定开发人员的问题。

回答by Julian Soro

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”,您是否尝试过使用“localhost”?

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

另外,尝试将端口设置为 1433,使用 $db['dbname']['port'] = 1433;

回答by DanielGomes

I had the same problem solved by setting

我通过设置解决了同样的问题

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

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

回答by Soumyaranjan Rath

Make 1. $db['default']['pconnect'] = FALSE;. Then go to system/database/drivers/sqlsrv/sqlsrv_driver.php

使 1 $db['default']['pconnect'] = FALSE;.. 然后去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);
}