简体   繁体   English

CodeIgniter MSSQL连接

[英]CodeIgniter MSSQL connection

I'm working on a web project that is to be deployed on a 64bit Windows 2008 Server machine running IIS 7.5 and PHP 5.3.8. 我正在开发一个Web项目,该项目将部署在运行IIS 7.5和PHP 5.3.8的64位Windows 2008 Server计算机上。 The database on the system is Microsoft SQL Server 2008 R2. 系统上的数据库是Microsoft SQL Server 2008 R2。 I'm developing the application on the CodeIgniter 2.1.0 framework, and I'm a bit stumped on getting it to connect to the SQL Server. 我正在CodeIgniter 2.1.0框架上开发应用程序,我有点难以让它连接到SQL Server。

I've tried using both the MSSQL, ODBC and SQLSRV database drivers, and have encountered three separate errors, for each different driver. 我已经尝试使用MSSQL,ODBC和SQLSRV数据库驱动程序,并且遇到了三个单独的错误,每个不同的驱动程序。

Here is my configuration for ODBC: 这是我的ODBC配置:

$db['default']['hostname'] = 'SA';
$db['default']['username'] = 'petre';
$db['default']['password'] = 'start';
$db['default']['database'] = 'petre';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

I have the DNS for SA defined under Data Sources, and I'm sure that the username and password are both valid, and that the server accepts Mixed authentication(Windows + SQL authentication). 我在数据源下定义了DNS for SA,我确信用户名和密码都有效,并且服务器接受混合身份验证(Windows + SQL身份验证)。

I'm auto-loading the DB library and for any page I access I get: 我正在自动加载数据库库,对于我访问的任何页面,我得到:

Unable to connect to your database server using the provided settings.
Filename: C:\inetpub\wwwroot\system\database\DB_driver.php
Line Number: 124

If I try to connect via MSSQL, I just get a blank page, no matter what. 如果我尝试通过MSSQL连接,我只是得到一个空白页,无论如何。

If I try using SQLSRV using the following params: 如果我尝试使用以下参数使用SQLSRV:

$db['default']['hostname'] = '127.0.0.1';
$db['default']['username'] = 'petre';
$db['default']['password'] = 'start';
$db['default']['database'] = 'petre';
$db['default']['dbdriver'] = 'sqlsrv';

Even though I'm linking to the sqlsrv DLL file in php.ini, I get the following message: 即使我链接到php.ini中的sqlsrv DLL文件,我收到以下消息:

PHP Fatal error:  Call to undefined function sqlsrv_connect() in C:\inetpub\wwwroot\system\database\drivers\sqlsrv\sqlsrv_driver.php on line 76

I've been reading up on old posts and different views but I've yet to solve the problem. 我一直在阅读旧帖和不同意见,但我还没有解决问题。

I'm only looking for a solution for a single DB Driver - anything that gets it to connect is fine. 我只是在寻找单个数据库驱动程序的解决方案 - 任何能够连接它的东西都很好。 Does anyone have any advice on solving this? 有没有人有任何解决这个问题的建议?

For x86 win download http://www.microsoft.com/en-us/download/details.aspx?id=20098 for using with: 对于x86 win下载http://www.microsoft.com/en-us/download/details.aspx?id=20098使用:

$db['default']['dbdriver'] = 'sqlsrv';
use the php_sqlsrv_XX_ts_vcX.dll in php.ini extension

if your webserver and your database server are not on same server with your app, install this: 如果您的网络服务器和数据库服务器与您的应用不在同一台服务器上,请安装:

http://go.microsoft.com/fwlink/?LinkID=188400&clcid=0x409

and for linux as webserver: 对于linux作为webserver:
$db['default']['dbdriver'] = 'mssql'; $ db ['default'] ['dbdriver'] ='mssql';

download & install = php5-sybase + freetds
<br/>edit /usr/local/etc/freetds.conf
<br/>create pdo_dblib.so & php_mssql.so (if not allready exist on your extension dir), and apply to php.ini

sudo /etc/init.d/apache2 restart

and just dont forget to allow connection to your DB (default port for mssql is 1433) 并且不要忘记允许连接到您的数据库(mssql的默认端口是1433)

The error you are showing for the SQLSRV driver implies the DLL is never loading. 您为SQLSRV驱动程序显示的错误意味着DLL永远不会加载。 What does your php_info() say? 你的php_info()说什么?

Also, do you have the SQL Server Native Access Client (SNAC) 10 installed? 此外,您是否安装了SQL Server Native Access Client(SNAC)10? The SQLSRV driver requires it. SQLSRV驱动程序需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM