yii2 sqlserver 2008 连接

本文详细介绍了如何使用freetds在Linux环境下配置PHP连接MSSQL数据库的过程,包括freetds的安装与配置、测试连接、添加PHP扩展、数据库配置以及常见问题解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考文章

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的配置问题了

 

转载于:https://www.cnblogs.com/allen817/p/7230708.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值