yii2 sqlserver 2008 連接


參考文章

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

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

 

1.必需安裝freetds

配置

[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 密碼(用這個我是測試連接不上)

我是這樣測試的:  Cd 到  /usr/local/freetds/bin/tsql

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

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

 我的環境是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的配置問題了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM