Laravel和MS SQL Server数据库连接抛出错误“(3/3)QueryException找不到驱动程序". [英] Laravel and MS SQL Server Database connection is throwing the error "(3/3) QueryException could not find driver"

查看:170
本文介绍了Laravel和MS SQL Server数据库连接抛出错误“(3/3)QueryException找不到驱动程序".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Guys, I tried lots of things mentioned in Stackoverflow and laracasts for this issue but none worked, hence posting this in hope of getting some answer or advice.另外,提供的大多数内容都属于MYSQL,而不是MS SQL.

Guys, I tried lots of things mentioned in Stackoverflow and laracasts for this issue but none worked, hence posting this in hope of getting some answer or advice. Also, most of the things provided belongs to MYSQL not for MS SQL.

我正在使用Windows 10,并使用Laravel连接到我的Microsoft SQL Server 2012 Express版本.

I am using Windows 10 and using Laravel to connect to my Microsoft SQL Server 2012 Express edition.

我的.erv文件如下:

I have the .erv file as following:

DB_CONNECTION=sqlsrv
DB_HOST=W1234567\SQLEXPRESS
DB_PORT=1433
DB_DATABASE=My_Database_Name
DB_USERNAME=sa
DB_PASSWORD=My_Password

给出的详细信息是正确的,但是当我运行一个简单的查询时,我的Laravel Model中收到以下错误消息:

The given details are correct but when I am running a simple query I am getting following error message in my Laravel Model:

(3/3) QueryException
could not find driver (SQL: SELECT COUNT(*) AS count FROM TBL_Data
WHERE ACTIVE_IND = 1
)

我的WAMP运行正常,已将SQLSRV文件添加到我的WAMP中.

I have the WAMP running properly, I have added the SQLSRV file to my WAMP.

整个过程运行良好,现在我将代码移到了其他系统,我得到了这个错误(两个系统具有相同的凭据,但更改的只是我更改过的服务器名称),因此代码应该可以正常工作没有做任何更改.

The entire thing was working fine, now I moved the code to different system there I am getting this error (Both the system has the same credentials only change is the Server name which I have changed) so the code should work properly as there are no changes done.

我尝试检查SQL Server Configuration Manager中的SQL Server TCP/IP端口号,并将其更改为1433仍然没有运气.

I tried checking the SQL Server TCP/IP port number in SQL Server Configuration Manager and changed it to 1433 still no luck.

我在这里检查了大多数答案,这些答案属于PDO异常,并要求人们取消注释extension=php_pdo_mysql.dll的部分,但在我来说,它的SQL Server和正常的wamp正常工作仅是LARAVEL的问题.

I checked most of the answers here and they belong to PDO exception and asked people to uncomment the part extension=php_pdo_mysql.dll but in my case its SQL Server and normal wamp is working perfectly only seems to be problem with LARAVEL.

有人可以为此提供解决方案吗?

Can anyone provide the solutions for this?

Edited part below with some more info:

我检查了给定的凭据是否正确,以及是否能够使用控制器中的一个简单功能连接到数据库: 我的路线:Route::get('/Test', 'My_Controller@Test');

I checked if the credentials given are correct and if I am able to connect to db using a simple function in controller: My Route: Route::get('/Test', 'My_Controller@Test');

我的控制器:

public function Test(Request $request)
{
  if(DB::connection()->getDatabaseName())
   {
    echo "connected successfully to database ".DB::connection()->getDatabaseName();
  }

}

Chrome窗口中的输出:connected successfully to database My_Database_Name

Output in the Chrome window: connected successfully to database My_Database_Name

从上面的消息中我们可以看到,我能够正确连接,但是在运行查询时仍然出现错误:

As we see from above message, I am able to connect properly but still when I run the query I get the error:

(3/3) QueryException
could not find driver (SQL: SELECT * FROM TBL_Data WHERE ACTIVE_IND = 1 )

在控制器中添加了phpinfo();并尝试访问该URL,并获得了与PDO相关的以下信息:

Added the phpinfo(); in the controller and tried to hit the URL and got the following info related to the PDO:

PDO support enabled

PDO drivers mysql, SQLite

未启用SQLSRV,这是引起问题的原因吗?

SQLSRV is not enabled here is this something which is causing the issue?

推荐答案

所以我终于能够弄清楚这个问题,将其发布出来,这样可以帮助打了好几天的人并撕开头发找到解决方案

So I was finally able to figure out the issue, Posting the same so it will help someone who has struck for days and ripping their hair out to find the solution.

  1. 确保在连接时已在Laravel中提供正确的端口,并且该端口与一个SQL Server Configuration Manager TCP/IP相同.

  1. Make sure you have given proper port in the Laravel while connection and its same as the one SQL Server Configuration Manager TCP/IP.

确保在SQL Server Configuration Manager中启用了TCP/IP.

Make sure your TCP/IP is Enabled in SQL Server Configuration Manager.

我的php.ini文件中缺少一些Extension,因此我将这些扩展名复制粘贴到WAMP的PHP中的php.ini文件中.

I had some Extension which were missing in my php.ini file so I copy pasted these extension on to my php.ini file in the PHP of WAMP.

extension = php_bz2.dll

extension=php_bz2.dll

extension = php_curl.dll

extension=php_curl.dll

extension = php_sqlsrv_56_ts.dll

extension=php_sqlsrv_56_ts.dll

extension = php_sqlsrv_56_nts.dll

extension=php_sqlsrv_56_nts.dll

extension = php_com_dotnet.dll

extension=php_com_dotnet.dll

; extension = php_enchant.dll

;extension=php_enchant.dll

extension = php_fileinfo.dll

extension=php_fileinfo.dll

; extension = php_ftp.dll

;extension=php_ftp.dll

extension = php_gd2.dll

extension=php_gd2.dll

extension = php_gettext.dll

extension=php_gettext.dll

extension = php_gmp.dll

extension=php_gmp.dll

extension = php_intl.dll

extension=php_intl.dll

extension = php_imap.dll

extension=php_imap.dll

; extension = php_interbase.dll

;extension=php_interbase.dll

extension = php_ldap.dll

extension=php_ldap.dll

extension = php_mbstring.dll

extension=php_mbstring.dll

extension = php_exif.dll;必须在mbstring之后,因为它取决于它

extension=php_exif.dll ; Must be after mbstring as it depends on it

extension = php_mysqli.dll

extension=php_mysqli.dll

extension = php_odbc.dll

extension=php_odbc.dll

extension = php_openssl.dll

extension=php_openssl.dll

; extension = php_pdo_firebird.dll

;extension=php_pdo_firebird.dll

extension = php_pdo_mysql.dll

extension=php_pdo_mysql.dll

; extension = php_pdo_oci.dll

;extension=php_pdo_oci.dll

; extension = php_oci8_12c.dll;与Oracle Database 12c Instant Client一起使用

;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client

extension = php_pdo_odbc.dll

extension=php_pdo_odbc.dll

; extension = php_pdo_pgsql.dll

;extension=php_pdo_pgsql.dll

extension = php_pdo_sqlite.dll

extension=php_pdo_sqlite.dll

; extension = php_pgsql.dll

;extension=php_pgsql.dll

; extension = php_phpdbg_webhelper.dll

;extension=php_phpdbg_webhelper.dll

; extension = php_shmop.dll

;extension=php_shmop.dll

每次在Laravel的.env文件中进行更改时,都需要刷新它,否则它将仍然使用您提供的旧数据.

Every time you change something in the .env file in the Laravel, you need to refresh it otherwise it will still use the old data which you have provided.

php artisan config:clear

php artisan config:cache

重新启动WAMP服务器和Laravel服务器php artisan server

Restart the WAMP Server and the Laravel server php artisan server

我在Laravel中的.env文件:

My .env file in the Laravel:

DB_CONNECTION = sqlsrv

DB_CONNECTION=sqlsrv

DB_HOST = 127.0.0.1

DB_HOST=127.0.0.1

DB_PORT = 1433

DB_PORT=1433

DB_DATABASE =数据库名称

DB_DATABASE=DataBase_Name

DB_USERNAME = sa

DB_USERNAME=sa

DB_PASSWORD = MyPass

DB_PASSWORD=MyPass

希望这对你们有用,否则一切顺利,并尝试找到分辨率,也请让我知道.

Hopefully this should work for you guys, Otherwise all the best and try to find the resolution and please let me also know.

这篇关于Laravel和MS SQL Server数据库连接抛出错误“(3/3)QueryException找不到驱动程序".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆