[英]Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
I'm new to web development and today, just as I was practicing with a local server (using XAMPP Apache and MySQL services), I got this error message:我是 Web 开发的新手,今天,就像我在本地服务器上练习(使用 XAMPP Apache 和 MySQL 服务)一样,我收到了以下错误消息:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\xampp\htdocs\blog\resources\query functions.php:3 Stack trace: #0 C:\xampp\htdocs\blog\resources\query functions.php(3): PDO->__construct('dblib:host=loca...', 'admin', 'root') #1 C:\xampp\htdocs\blog\resources\main.php(23): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\blog\resources\query functions.php on line 3
There's index.php file in C:\\xampp\\htdocs\\blog that includes main.php
from C:\\xampp\\htdocs\\blog\\resources
, then main.php includes another file in same directory called queryfunctions.php
. C:\\xampp\\htdocs\\blog that includes main.php
有 index.php 文件C:\\xampp\\htdocs\\blog that includes main.php
来自C:\\xampp\\htdocs\\blog\\resources
main.php ,然后 main.php 包含位于同一目录中的另一个名为queryfunctions.php
文件。 main.php only has one line of code and that is to include queryfunctions.php
. main.php 只有一行代码,即包含queryfunctions.php
。 Then in that file I wrote this:然后在那个文件中我写了这个:
$database = new PDO('dblib:host=localhost;dbname=test;charset=UTF-8', "admin", "root");
And then it gives me the error whenever I go to test it.然后每当我去测试它时它都会给我错误。 I've read through a couple of questions and answers already, but none helped.我已经阅读了几个问题和答案,但没有一个帮助。 In my PHP info, these are the PDO drivers installed: mysql, odbc, sqlite, sqlite2
.在我的 PHP 信息中,这些是安装的 PDO 驱动程序: mysql, odbc, sqlite, sqlite2
。
PDO Driver for MySQL: Client API Version mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $. MySQL 的 PDO 驱动程序:客户端 API 版本 mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $。
If you are trying to connect to MySQL, use the MySQL connection string:如果您尝试连接到 MySQL,请使用 MySQL 连接字符串:
$database = new PDO('mysql:host=localhost;dbname=test', "admin", "root");
The dblib
driver you are using is for Microsoft SQL and Sybase.您使用的dblib
驱动程序用于 Microsoft SQL 和 Sybase。 If you are using XAMPP, chances are you are using MySQL not Microsoft SQL.如果您使用的是 XAMPP,则您使用的是 MySQL 而不是 Microsoft SQL。 If you are using Microsoft SQL, you will need to download and install it: http://www.php.net/manual/en/ref.pdo-dblib.php如果您使用的是 Microsoft SQL,则需要下载并安装它: http : //www.php.net/manual/en/ref.pdo-dblib.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.