与SQL Server数据库连接Laravel总是显示错误“找不到驱动程序”。

发布于 2025-01-19 12:36:09 字数 2701 浏览 4 评论 0 原文

我想将 Laravel(版本 8)与 SQL Server 数据库(SQL Server 2008 R2)连接。

我已经完成安装并按照一些教程进行操作,例如 以下,其中我安装的版本适配SQL Server 2008 R2,如本指南

  1. 安装了适用于 SQL Server 的 Microsoft® ODBC 驱动程序 17(我选择版本 17 是因为这个

  2. 通过获取 2 个文件安装 PHP 驱动程序版本 5.6,即我从 php_pdo_sqlsrv_73_ts.dll 和 php_sqlsrv_73_ts.dll rel="nofollow noreferrer">这里(我根据此)

  3. 我把上面2个文件放在C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext

  4. 我在 php.ini 中启用了扩展,像这样:extension=pdo_sqlsrv_73_ts扩展名=sqlsrv_73_ts。它成功了,当我检查 php.info 时,它显示 pdo_sqlsrv

  5. 然后我在 Laravel 的 .env 上配置了数据库连接,如下所示(我已经创建了一个具有该名称的数据库):

DB_CONNECTION=sqlsrv
DB_HOST=192.168.101.103:86
数据库端口=1433
DB_DATABASE=testlaravel
DB_USERNAME=faisallocal
DB_PASSWORD=faisallocal
  1. 然后我在终端上运行 php artisan migrate 。

但我总是收到这样的错误:

[照亮\数据库\QueryException

无法找到驱动程序(SQL:select * from sys.sysobjects where id = object_id(migrations) 和 xtype in ('U', 'V'))

在 C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712 708▕ //如果尝试运行查询时发生异常,我们将格式化错误 第709章 710▕ // 对开发人员有更多帮助,而不仅仅是数据库错误。 第711章 712、第712章 第713章【714】 第715章 第716章 ▕}

1 C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 PDOException::(“找不到驱动程序”)

2 C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 PDO::__construct("dblib:host=192.168.101.103:86:1433;dbname=testlaravel;charset=utf8", “faisallocal”,“faisallocal”,[])]

我错过了什么? 我在本地做了这个测试,我有不同版本的 XAMPP 和 Laragon,但如果我有不同的端口不是可以吗?

请帮助任何有经验并对此有建议的人,我已经被困在这一点上好几个星期了..

谢谢

I want to connect Laravel (version 8), with a SQL Server database (SQL Server 2008 R2).

I've done the installation and followed some tutorials with steps like the following, where the version I installed adapts to SQL Server 2008 R2, like this guide :

  1. Installed Microsoft® ODBC Driver 17 for SQL Server (I chose version 17 because of this)

  2. Installed PHP Driver version 5.6 by taking 2 files, namely php_pdo_sqlsrv_73_ts.dll and php_sqlsrv_73_ts.dll which I got from here (I chose version 5.6 based on this)

  3. I put the above 2 files in C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext

  4. I enabled the extension in php.ini, like this: extension=pdo_sqlsrv_73_ts,
    extension=sqlsrv_73_ts. It succeed, When I checked in php.info, it says pdo_sqlsrv

  5. Then I configured the database connection on Laravel's .env like this (I've created a database with that name):

DB_CONNECTION=sqlsrv
DB_HOST=192.168.101.103:86
DB_PORT=1433
DB_DATABASE=testlaravel
DB_USERNAME=faisallocal
DB_PASSWORD=faisallocal
  1. Then I run php artisan migrate on terminal.

But I always get an error like this:

[Illuminate\Database\QueryException

could not find driver (SQL: select * from sys.sysobjects where id =
object_id(migrations) and xtype in ('U', 'V'))

at
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
708▕ // If an exception occurs when trying to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) { 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e 714▕ );
715▕ }
716▕ }

1
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")

2
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("dblib:host=192.168.101.103:86:1433;dbname=testlaravel;charset=utf8",
"faisallocal", "faisallocal", [])]

What did I miss?
I did this test locally, and I have XAMPP as well as Laragon with different versions, but wouldn't it be okay if I had a different port?

Please help anyone who has experience and has advice on this, I've been stuck at this point for weeks..

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假扮的天使 2025-01-26 12:36:09

php_pdo_sqlsrv_73_ts.dll取决于您版本的php

:php_pdo_sqlsrv_73_ts.dll用于

下一个链接中的php 7.3,您可以看到此信息。

https://lealen.microsoft.com/en-us/sql/connect/php/system-semstem-requirentess-for-the-php--php-sql-driver?view = sql-server-server-ver15

php_pdo_sqlsrv_73_ts.dll It depends of your version of php

for example: php_pdo_sqlsrv_73_ts.dll is for php 7.3

in the next link you can see this information.

https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15

往日 2025-01-26 12:36:09

因此,这一切都是由于检测到的PHP和SQL Server驱动程序的不同版本而发生的。

有关信息,我有3台本地服务器,即:

  1. XAMPP 1.7.3,
  2. XAMPP 3。?。 (我忘记了版本的详细信息
  3. 和laragon。

发生的问题是,当我想使用Laragon Server 开发应用程序时,我使用本地终端/命令提示符(快捷方式:Windows + CMD ),PHP版本来自其他本地服务器将相互碰撞。

当我运行laravel命令时,检查PHP版本或其他任何内容时,本地命令提示将我引导到我已安装的XAMPP版本,因此任何 .dll 或您在Laragon中安装的插件被检测到!

最后,我能够根据我想要的版本完成安装并执行很多CMD命令,这是如何使用Laragon的内置CMD/终端(在Laragon应用程序下单击终端

从此终端中,您安装的所有 .dll 插件以及您输入的所有CMD命令都将匹配您使用的laragon版本,它们不会被丢弃到另一家本地服务器! :d

So this all happened because of the detected different versions of PHP and SQL Server drivers.

For information, I have 3 local servers, namely:

  1. XAMPP 1.7.3,
  2. XAMPP 3.?.? (I forgot the version details),
  3. and Laragon.

The problem that occurs is, when I want to develop apps using the Laragon server AND I use the local Terminal/Command Prompt (Shortcut: Windows + CMD), the PHP versions from other local servers will collide with each other.

When I run a Laravel command, check the PHP version, or whatever, the local Command Prompt directs me to the version of XAMPP above that I have installed, so any .dll or plugins you install in Laragon won't be detected!

Finally I was able to finish my installation and do a lot of CMD commands according to the version I want, is how to use the built-in CMD/Terminal from Laragon (Click on Terminal under Laragon application)

From this Terminal, all the .dll plugins that you install, and all the cmd commands that you enter, will match the Laragon version you are using, they won't be strayed to another local server! :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文