我想将 Laravel(版本 8)与 SQL Server 数据库(SQL Server 2008 R2)连接。
我已经完成安装并按照一些教程进行操作,例如 以下,其中我安装的版本适配SQL Server 2008 R2,如本指南:
-
安装了适用于 SQL Server 的 Microsoft® ODBC 驱动程序 17(我选择版本 17 是因为这个)
-
通过获取 2 个文件安装 PHP 驱动程序版本 5.6,即我从 php_pdo_sqlsrv_73_ts.dll 和 php_sqlsrv_73_ts.dll
rel="nofollow noreferrer">这里(我根据此)
-
我把上面2个文件放在C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext
-
我在 php.ini 中启用了扩展
,像这样:extension=pdo_sqlsrv_73_ts
,
扩展名=sqlsrv_73_ts
。它成功了,当我检查 php.info
时,它显示 pdo_sqlsrv
-
然后我在 Laravel 的 .env
上配置了数据库连接,如下所示(我已经创建了一个具有该名称的数据库):
DB_CONNECTION=sqlsrv
DB_HOST=192.168.101.103:86
数据库端口=1433
DB_DATABASE=testlaravel
DB_USERNAME=faisallocal
DB_PASSWORD=faisallocal
- 然后我在终端上运行 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 :
-
Installed Microsoft® ODBC Driver 17 for SQL Server (I chose version 17 because of this)
-
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)
-
I put the above 2 files in C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext
-
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
-
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
- 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
发布评论
评论(2)
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
因此,这一切都是由于检测到的PHP和SQL Server驱动程序的不同版本而发生的。
有关信息,我有3台本地服务器,即:
发生的问题是,当我想使用Laragon Server 和开发应用程序时,我使用本地终端/命令提示符(快捷方式:Windows + CMD ),PHP版本来自其他本地服务器将相互碰撞。
当我运行laravel命令时,检查PHP版本或其他任何内容时,本地命令提示将我引导到我已安装的XAMPP版本,因此任何
.dll
或您在Laragon中安装的插件被检测到!最后,我能够根据我想要的版本完成安装并执行很多CMD命令,这是如何使用Laragon的内置CMD/终端(在Laragon应用程序下单击终端)
从此终端中,您安装的所有
.dll
插件以及您输入的所有CMD命令都将匹配您使用的laragon版本,它们不会被丢弃到另一家本地服务器! :dSo this all happened because of the detected different versions of PHP and SQL Server drivers.
For information, I have 3 local servers, namely:
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