Windows IIS - PHP PDO Mysql 找不到驱动程序 [英] Windows IIS - PHP PDO Mysql Could not find driver
问题描述
我有以下代码可以从本地 PHP(Windows,使用 IIS)连接到 Mysql 数据库,
I have the following code to connect to a Mysql database from my local PHP (Windows, using IIS),
$dbhost = "xxxx.database.windows.net";
$dbname = "yyyy";
$dbuser = "uuuu";
$dbpass = "pppp";
$driver = "sqlsrv";
$connection = new PDO("$driver:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
php 信息是这样说的:
php info says this:
Loaded Configuration File C:\Program Files (x86)\IIS Express\PHP\v5.6\php.ini
我在这个 php.ini 文件中有以下内容
I have the following in this php.ini file
[WebPIChanges]
error_log=C:\Windows\temp\PHP56ForIISExpress_errors.log
upload_tmp_dir=C:\Windows\temp
session.save_path=C:\Windows\temp
cgi.force_redirect=0
cgi.fix_pathinfo=1
fastcgi.impersonate=1
fastcgi.logging=0
max_execution_time=300
date.timezone=Europe/Minsk
extension_dir="C:\Program Files (x86)\iis express\PHP\v5.6\ext\"
[ExtensionList]
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_imap.dll
extension=php_tidy.dll
extension=php_sqlsrv.dll
此文件存在:C:\Program Files (x86)\IIS Express\PHP\v5.6\ext\php_pdo_mysql.dll
This file exists: C:\Program Files (x86)\IIS Express\PHP\v5.6\ext\php_pdo_mysql.dll
为什么我会收到找不到驱动程序"的错误消息?我的应用程序池可以运行 32 位或 64 位.
Why do I get a "could not find driver" error? My application pool can run 32-bit or 64-bit.
推荐答案
有两点不对.我有错误的连接字符串.应该是
Two things were wrong. I had the wrong connection string. Should have been
$connection = new PDO("$driver:Server=$dbhost;Database=$dbname",$dbuser,$dbpass);
我也缺少 sql server 的扩展!!!
I was also missing the extension for sql server!!!
extension=php_pdo_sqlsrv_56_nts.dll
我的 PC 上什至没有 5.6 版,必须从这里下载:
I didn't even have version 5.6 on my PC had to download it from here:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=20098
这篇关于Windows IIS - PHP PDO Mysql 找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!