yii2 sqlserver 2008 鏈接

參考文章php

http://www.cnblogs.com/facetwitter/p/6444706.html?utm_source=itdadao&utm_medium=referralhtml

http://www.cnblogs.com/jiechn/p/4841865.htmlnginx

 

1.必需安裝freetdssql

配置數據庫

[myconfig]
host = 192.168.2.22
port = 1433
tds version = 8.0
client chaeset = UTF-8
服務器

測試 :/usr/local/freetds/bin/tsql -H 數據庫服務器IP  -p 端口號 -U 用戶名 -P 密碼(用這個我是測試鏈接不上)yii

我是這樣測試的:  Cd 到  /usr/local/freetds/bin/tsqlphp-fpm

  tsql -S myconfig -U name    -P password  能鏈接上   ,簡單的 命令 use database;top 10 * from table;測試

3接下來添加php的mssq和pdo_dblib擴展spa

 個人環境是nginx 的因此重啓完nginx 重啓 php-fpm

4.最後數據庫配置

'class' => 'yii\db\Connection',
    'dsn' => 'dblib:host=myconfig;dbname=dbname',//這裏我用ip他不行,用這個名稱就能夠,我也不知道 ,這個要是不行,試下下面這個

   //'dsn' => 'sqlsrv:Server=myconfig;Database=dbname',
    'username' => '',
    'password'=>'',
    //'charset'=>'utf8',
    //'persistent'=> false,
    'enableSchemaCache' => true,
    // Duration of schema cache.
    'schemaCacheDuration' => 300,
    // Name of the cache component used. Default is 'cache'.
    'schemaCache' => 'cache',

若是報找不到驅動的就先確保裝了上面的擴展和模塊,重啓nginx,php-fpm,再就是dsn的配置問題了

相關文章
相關標籤/搜索