相干版本
体系ubuntu 16.04, 运用的PHP版本是7.0.30, sqlserver 2012, freetds为0.92 Laravel5.5和5.4都测试过了
装置php驱动
sudo apt-get install php7.0-odbc sudo apt install php7.0-sybase
装置freetds
sudo apt-get install freetds-bin freetds-common tdsodbc odbcinst unixodbc unixodbc-dev sudo mv /etc/odbcinst.ini /etc/odbcinst.ini.bak sudo cp /usr/share/tdsodbc/odbcinst.ini /etc/
设置freetds
sudo vim /etc/freetds/freetds.conf
修正设置
[global] tds version = 8.0 # TDS version, ref <a href="http://www.freetds.org/userguide/choosingtdsprotocol.htm" target="_blank">this</a>. client charset = UTF-8 text size = 20971520 [Server2012] #自定义称号,背面须要运用 host = {yourdomain}.database.windows.net // ip地点或域名 port = 1433 tds version = 8.0 #8.0为2012其他自行测试
测试SQLSERVER
TDSVER=8.0 tsql -H my_server_host -p 1433 -U my_user -P my_password -D my_database
设置Laravel5
翻开config/database.php
在connections
中增加设置,驱动运用sqlsrv
'mssql' => [ 'driver' => 'sqlsrv', 'host' => 'Server2012', // 这个对应freetds.conf的设置称号 'port' => '1433', 'database' => env('DB_DATABASE', '数据库'), 'username' => env('DB_USERNAME', '用户'), 'password' => env('DB_PASSWORD', '暗码'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, ],
多数据库
假如你用了mysql又想用sqlserver的部分信息,个人项目缘由,但平常的做法是sqlserver的体系写API让Mysql体系的挪用,但这次偷偷懒,就两个一同用了
在Model中 到场protected $connection = 'mssql';
并运用protected $table = 'EMPLOYEE';
指明数据表,就能够不必每次在Controller写衔接了.
相干引荐:
laravel框架在数据统计画图的完成
Laravel框架中Echo的运用历程
以上就是laravel5怎样经由历程freetds来衔接到sqlserver(代码)的细致内容,更多请关注ki4网别的相干文章!