Jamie
Jamie

Reputation: 10886

Can't connect to database with laravel 5

I'm trying to connect to my mssql database with laravel 5 but it's not working. I've tried to connect with different mssql databases so it's not a firewall issue. Also my credentials are correct. I found on google that you need SQL Server Native Client 11.0 and I've already installed that.

This is my connection array in config/database.php:

'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => env('nvt'),
            'database' => env('nvt'),
            'username' => env('nvt'),
            'password' => env('nvt'),
            'charset'  => 'utf8',
            'prefix'   => '',
        ],

And I've set the default to "sqlsrv" :

'default' => env('sqlsrv','sqlsrv'),

But when I'm trying to create a table I receive the error:

PDOException in Connector.php line 50: could not find driver

What could be wrong???

EDIT:

I've installed pdo for sqlsrv from here: http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

And I added it to my php.ini file: extension=\Installaties\php_pdo_sqlsrv_53_nts.dll

But stil I receive the error?

Upvotes: 4

Views: 1728

Answers (4)

Nkwaten
Nkwaten

Reputation: 31

You may try any of the following solutions

  1. Check that you have entered the right connection parameters. Test by connecting to the DB with a client tool.
  2. Make sure you have the right version of sqlsrv configured for your machine. Check the PHP logs to be sure your web server was able to load the extension correctly.
  3. Set the port to null in your env file

As a tip, I won't advise anyone to set the connection parameters anywhere but in the .env (Setting it in config/database is a security risk).

Upvotes: 0

John Garcia
John Garcia

Reputation: 1

I encountered your problem the last time I tried my connection in sqlsrv. I am using xampp. Try putting yung php_pdo_sqlsrv_53_nts.dll in the ext folder, replace extension=\Installaties\php_pdo_sqlsrv_53_nts.dll with extension=php_pdo_sqlsrv_53_nts.dll and try installing odbc 11 on your computer. It worked for me but not sure why. (not an expert) if it worked good to help a fellow person and if not, sorry for the trouble. Thank you for the time reading.

Upvotes: 0

MasoodRehman
MasoodRehman

Reputation: 715

Try to remove the eve() method, i mean use the following method

'sqlsrv' => [
        'driver'   => 'sqlsrv',
        'host'     => 'nvt',
        'database' => 'nvt',
        'username' => 'nvt',
        'password' => 'nvt',
        'charset'  => 'utf8',
        'prefix'   => '',
    ],

Upvotes: 1

Jason Spick
Jason Spick

Reputation: 6088

I ran into a similar issue. Try putting in the server info directly rather than using env. If it works, then you know Laravel is having an issue reading the .env file.

Upvotes: 0

Related Questions