Can't connect to database with laravel 5

≡放荡痞女 提交于 2021-01-27 07:16:43

问题


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?


回答1:


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



回答2:


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.




回答3:


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.




回答4:


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).



来源:https://stackoverflow.com/questions/31342899/cant-connect-to-database-with-laravel-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!