用户
 找回密码
 入住 CI 中国社区
搜索
查看: 7109|回复: 4
收起左侧

ci下配置sqlsrv

[复制链接]
发表于 2012-5-13 01:14:38 | 显示全部楼层 |阅读模式
本帖最后由 幸福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



发表于 2012-5-13 17:01:50 | 显示全部楼层
就是不支持 pconnect 呗?
一般很少有 PHP 配合 mssql 的,不配套,呵呵
 楼主| 发表于 2012-5-14 00:14:41 | 显示全部楼层
没办法    MSSQL 看着舒服点
发表于 2012-5-14 01:04:36 | 显示全部楼层
幸福de米饭 发表于 2012-5-14 00:14
没办法    MSSQL 看着舒服点

看着舒服点?哪里舒服?我怎么没发现 MSSQL 有什么特别的优势呢?呵呵
发表于 2012-10-11 23:34:39 | 显示全部楼层
请问config中的database的配置应该怎么写?
  1. $db['default']['hostname'] = "localhost";//???
  2. $db['default']['username'] = "";
  3. $db['default']['password'] = "";
  4. $db['default']['database'] = "";
  5. $db['default']['dbdriver'] = "mssql";//???
复制代码
注释了???的两行怎么写?多谢~

本版积分规则