本帖最后由 幸福de米饭 于 2012-5-13 01:22 编辑
ci下配置 sqlsrv
我这里就按照 php 5.2+apache+mssql为例
下载SQLSRV20 http://download.microsoft.com/download/C/D/B/CDB0A3BB-600E-42ED-8D5E-E4630C905371/SQLSRV20.EXE
下载sqlncli http://go.microsoft.com/fwlink/?LinkID=188400&clcid=0x409 (x86)
http://go.microsoft.com/fwlink/?LinkID=188401&clcid=0x409 (x64)
不安装sqlncli 可能会报 如下错误
{The SQL Server Driver for PHP requires the SQL Server 2008 Native Client ODBC Driver (SP1 or
later) to communicate with SQL Server. That ODBC Driver is not currently installed. Access the following URL to
download the SQL Server 2008 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712}
解压SQLSRV20 找到(php_sqlsrv_52_ts_vc6.dll) 复制到 盘符:/php目录/ext 里面
打开php.ini 写下 extension=php_sqlsrv_52_ts_vc6.dll
重启 apache sqlserver
先将 根目录 index.php改为如下代码
PHP复制代码
$dbbase='test';
$uid='sa';
$pwd='sa';
$connectionInfo=array("Database"=>$dbbase,"UID"=>$uid,"PWD"=>$pwd);
$serverName="127.0.0.1";
if(!($conn=sqlsrv_connect ($serverName,$connectionInfo))){
echo "Connection could not be established. ";
die(print_r(sqlsrv_errors (),true));
}else{echo "sql2005 连接成功";}
复制代码
这时候连接成功 但是ci下连接sqlsrv的话会报错
打开 ./system/database/drivers/mssql/mssql_driver.php 该文件
修改 db_pconnect()函数
PHP复制代码
function db_pconnect()
{
return $this->db_connect(TRUE);
}
复制代码
ok了
This section lists the drivers that are installed for version 2.0 and version 3.0 of the Microsoft Drivers for PHP for SQL Server. PHP version 5.2 is not supported in version 3.0 of the Microsoft Drivers for PHP for SQL Server. Follow the installation instructions in Loading the Driver to configure the driver for use with the PHP runtime. Microsoft Drivers 2.0 for PHP for SQL Server installs several versions of the driver:
Driver file
| PHP version
| Thread safe?
| Use with PHP .dll
| php_sqlsrv_53_nts_vc6.dll
php_pdo_sqlsrv_53_nts_vc6.dll
| 5.3
| no
| php5.dll
| php_sqlsrv_53_nts_vc9.dll
php_pdo_sqlsrv_53_nts_vc9.dll
| 5.3
| no
| php5.dll
| php_sqlsrv_53_ts_vc6.dll
php_pdo_sqlsrv_53_ts_vc6.dll
| 5.3
| yes
| php5ts.dll
| php_sqlsrv_53_ts_vc9.dll
php_pdo_sqlsrv_53_ts_vc9.dll
| 5.3
| yes
| php5ts.dll
| php_sqlsrv_52_nts_vc6.dll
php_pdo_sqlsrv_52_nts_vc6.dll
| 5.2
| no
| php5.dll
| php_sqlsrv_52_ts_vc6.dll
php_pdo_sqlsrv_52_ts_vc6.dll
| 5.2
| yes
| php5ts.dll
|
If the name of the driver file contains "vc9", it should be used with a PHP version compiled with Visual C++ 9.0. Microsoft Drivers 3.0 for PHP for SQL Server installs several versions of the driver:
Driver file
| PHP version
| Thread safe?
| Use with PHP .dll
| php_sqlsrv_53_nts.dll
php_pdo_sqlsrv_53_nts.dll
| 5.3
| no
| php5.dll
| php_sqlsrv_53_ts.dll
php_pdo_sqlsrv_53_ts.dll
| 5.3
| yes
| php5ts.dll
| php_sqlsrv_54_nts.dll
php_pdo_sqlsrv_54_nts.dll
| 5.4
| no
| php5.dll
| php_sqlsrv_54_ts.dll
php_pdo_sqlsrv_54_ts.dll
| 5.4
| yes
| php5ts.dll
|
|