Laravel 5.3 連接 SQL Server

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

二、config/database.ph的connections增加

'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' => '',
],

三、.env修改連線

DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1433
DB_DATABASE=dbname
DB_USERNAME=dbuser
DB_PASSWORD=dbpassword

四、測試是否可以產生
routes/web.php

Route::get('/', function () {
    var_dump( DB::table('tablename')->first() );
});