Laravel 5.3 連接 SQL Server

一、下載 https://github.com/superlevin/xamppforlaravel

二、config/database.ph的connections增加
[php]
‘sqlsrv’ => [
‘driver’ => ‘sqlsrv’,
‘host’ => env(‘DB_HOST’, ‘localhost’),
‘database’ => env(‘DB_DATABASE’, ‘dbname’),
‘username’ => env(‘DB_USERNAME’, ‘dbuser’),
‘password’ => env(‘DB_PASSWORD’, ‘dbpassword’),
‘charset’ => ‘utf8’,
‘prefix’ => ”,
],
[/php]
三、.env修改連線
[php]
DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1433
DB_DATABASE=dbname
DB_USERNAME=dbuser
DB_PASSWORD=dbpassword
[/php]
四、測試是否可以產生
routes/web.php
[php]
Route::get(‘/’, function () {
var_dump( DB::table(‘tablename’)->first() );
});
[/php]