mardi 5 avril 2016

Laravel 5.2 connect to MS SQL 2012

I am using Laravel 5.2. Out-Of-The-Box it does not have a MS SQL connection in the

config\database.php

so I made the following changes

'default' => env('DB_CONNECTION', 'sqlsrv'),
'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => '10.0.0.1', // Provide IP address here
        'database' => 'TheDatabase',
        'username' => 'Fred',
        'password' => 'Flintstone',
        'prefix' => '',
    ],

How do I test if this is working?

I went and made a controller called

TheDatabaseController

and put the following code into it

<?php

namespace App\Http\Controllers;

use DB;
use App\Http\Controllers\Controller;

class TheDatabaseController extends Controller
{
    public function index()
{
    $stats = DB::table('sometable')->get();
    echo $stats;
}
}

I try to run the page and I get the following error:

Fatal error: Class 'App\Http\Controllers\Controller' not found in ...\app\Http\Controllers\TheDatabaseController.php on line 9

Where am I going wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire