How does laravel5 connect to sqlserver through freetds (code)
This article introduces to you about laravel5 connecting to sqlserver through freetds. It has certain reference value. I hope it can help friends in need.
Related versions
The system is ubuntu 16.04, the PHP version used is 7.0.30, sqlserver 2012, freetds is 0.92 Laravel5.5 and 5.4 have been tested
Install php driver
sudo apt-get install php7.0-odbc sudo apt install php7.0-sybase
Install 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/
Configure freetds
sudo vim /etc/freetds/freetds.conf
Modify configuration
[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其他自行测试
Test SQLSERVER
TDSVER=8.0 tsql -H my_server_host -p 1433 -U my_user -P my_password -D my_database
Configure Laravel5
Openconfig/database.php
Add configuration in connections
, the driver uses 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, ],
Multiple databases
If you use mysql I also want to use some information of sqlserver for personal project reasons, but the general approach is to write an API for the sqlserver system to be called by the Mysql system, but this time I was lazy and used both together
Add ## to the Model #protected $connection = 'mssql';And use
protected $table = 'EMPLOYEE'; Specify the data table, so you don't need to write the connection in the Controller every time.
Implementation of laravel framework in data statistical drawing
Using process of Echo in Laravel framework
The above is the detailed content of How does laravel5 connect to sqlserver through freetds (code). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel - Artisan Commands - Laravel 5.7 comes with new way of treating and testing new commands. It includes a new feature of testing artisan commands and the demonstration is mentioned below ?

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Laravel - Artisan Console - Laravel framework provides three primary tools for interaction through command-line namely: Artisan, Ticker and REPL. This chapter explains about Artisan in detail.

Laravel - Pagination Customizations - Laravel includes a feature of pagination which helps a user or a developer to include a pagination feature. Laravel paginator is integrated with the query builder and Eloquent ORM. The paginate method automatical

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Method for obtaining the return code when Laravel email sending fails. When using Laravel to develop applications, you often encounter situations where you need to send verification codes. And in reality...

Running multiple PHP versions simultaneously in the same system is a common requirement, especially when different projects depend on different versions of PHP. How to be on the same...

Laravel schedule task run unresponsive troubleshooting When using Laravel's schedule task scheduling, many developers will encounter this problem: schedule:run...
