0

我是 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

C:\xampp\htdocs\blog that includes main.phpfrom中有 index.php 文件C:\xampp\htdocs\blog\resources,然后 main.php 在同一目录中包含另一个名为queryfunctions.php. main.php 只有一行代码,即包含queryfunctions.php. 然后在那个文件中我写了这个:

$database = new PDO('dblib:host=localhost;dbname=test;charset=UTF-8', "admin", "root");

然后每当我去测试它时它都会给我错误。我已经阅读了几个问题和答案,但没有任何帮助。在我的 PHP 信息中,这些是安装的 PDO 驱动程序:mysql, odbc, sqlite, sqlite2.

MySQL 的 PDO 驱动程序:客户端 API 版本 mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $。

4

1 回答 1

3

If you are trying to connect to MySQL, use the MySQL connection string:

$database = new PDO('mysql:host=localhost;dbname=test', "admin", "root");

The dblib driver you are using is for Microsoft SQL and Sybase. If you are using XAMPP, chances are you are using MySQL not 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

于 2012-06-07T20:19:38.290 回答