Yii连接mssql 数据库配置

http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05
下载MSSQL 的PDO 扩展,然后安装释放它到PHP的ext目录下面。
如果你在使用MSSQL2005,那么还需要安装Microsoft SQL Server 2008 R2 Native Client。
请阅读附件的CHM帮助文档里的System Requirements (Microsoft Drivers for PHP for SQL Server) 一节。
然后在 php.ini里面启动该扩展:
例如
PHP 5.3.5 使用 php_pdo_sqlsrv_53_ts_vc6.dllphp_sqlsrv_53_ts_vc6.dll
PHP 5.3.6 则使用 php_pdo_sqlsrv_53_ts_vc9.dllphp_sqlsrv_53_ts_vc9.dll

然后Yii的main config里面像下面这样配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// PDO MSSQL
'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=HOSTNAME\SQLEXPRESS;Database=Client',
      'username' => 'sa',
      'password' => '111',
      'charset' => 'GB2312',
      'tablePrefix' => 'tbl_',
),

译自:http://www.yiiframework.com/wiki/192/config-use-ms-sql-server-2005-2008/

更多
No Responses Post a comment

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS