windows下 php5.3如何鏈接mssql

由於php5.3之後php官方再也不支持php_mssql擴展,那麼php5.3之後如何鏈接mssql呢。 php

還好,microsoft 推出了一個sqlsrv擴展。安裝步驟以下: html

注,安裝以前請檢查你的操做系統是不是下面列表中之一,不然沒法安裝sqlsrv擴展 web

Windows Server 2003 Service Pack 1 sql

Windows XP Service Pack 3 安全

Windows Vista Service Pack 1 or later 服務器

Windows Server 2008 app

Windows Server 2008 R2 yii

Windows 7 post

第一步:下載sqlsrv擴展 ui

打開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

相關文章
相關標籤/搜索