因为php5.3以后php官方不再支持php_mssql扩展,那么php5.3以后如何连接mssql呢。
还好,microsoft 推出了一个sqlsrv扩展。安装步骤如下:
注,安装之前请检查你的操作系统是否是下面列表中之一,否则无法安装sqlsrv扩展
Windows Server 2003 Service Pack 1
Windows XP Service Pack 3
Windows Vista Service Pack 1 or later
Windows Server 2008
Windows Server 2008 R2
Windows 7
第一步:下载sqlsrv扩展
打开http://www.microsoft.com/en-us/download/details.aspx?id=20098 下载 SQLSRV20.EXE,点击安装,选择php扩展目录
查看自己的php 版本,可以通过查看phpinfo中的 Zend Extension Build API220090626,TS,VC9这里表示我的php版本是用vc9编译,线程安全的
故在php.ini配置
extension=php_sqlsrv_53_ts_vc9.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll
请根据自己的php版本,配置相应的扩展
第二步:sqlsrv扩展,依赖Microsoft SQL Server 2008 R2 Native Client 故需要安装
打开http://msdn.microsoft.com/en-us/library/cc296170%28SQL.90%29.aspx 选择 Download the X86 package下载,点击安装即可
第三步: 重启web服务器,查看sqlsrv扩展是否安装成功
安装之后,如何使用?
1. CI中database.php
$db['mssql']['hostname'] = ’168.192.*.*\\papers,143′; //注意这里的配置 ip\\实例名, 端口
$db['mssql']['username'] = ‘papers’;
$db['mssql']['password'] = ‘md3papers’;
$db['mssql']['database'] = ‘papers’;
$db['mssql']['dbdriver'] = ‘sqlsrv’;
$db['mssql']['dbprefix'] = ”;
$db['mssql']['pconnect'] = FALSE; //这里要设置为短连接
$db['mssql']['db_debug'] = TRUE;
$db['mssql']['cache_on'] = FALSE;
$db['mssql']['cachedir'] = ”;
$db['mssql']['char_set'] = ‘utf8′;
$db['mssql']['dbcollat'] = ‘utf8_general_ci’;
$db['mssql']['swap_pre'] = ”;
$db['mssql']['autoinit'] = TRUE;
$db['mssql']['stricton'] = FALSE;
2. yii protected/config/main.php
‘db’=>array(
// ‘class’=>’application.components.MyMsSqlConnection’,
// old MS PDO + MSSQL 2000:
//’connectionString’ => ‘mssql:host=HOSTNAME\SQLEXPRESS;dbname=Client’,
// new MS PDO + MSSQL 2005 2008
‘connectionString’ => ‘sqlsrv:Server=168.192.*.*\\papers,143;Database=Client’, //这里的配置类似CI
‘username’ => ‘sa’,
‘password’ => ’111′,
‘charset’ => ‘GB2312′,
‘tablePrefix’ => ‘tbl_’,
),
#以上参考
PHP5.3.5如何连接MSSql Server2005 http://www.cnblogs.com/kakaxi/archive/2011/08/05/2128437.html
http://www.php.net/manual/zh/ref.pdo-sqlsrv.connection.php
http://ihacklog.com/post/yii-config-use-ms-sql-server-2005-2008.html
来源:oschina
链接:https://my.oschina.net/u/733393/blog/110141