PHP致命错误:未捕获的PDOException:找不到驱动程序 [英] PHP Fatal error: Uncaught PDOException: could not find driver

查看:334
本文介绍了PHP致命错误:未捕获的PDOException:找不到驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用PDO从PHP连接到MySQL.但是,我收到此错误消息:

I have been trying to connect to MySQL from PHP using PDO. However, I get this error message:

PHP致命错误:未捕获的PDOException:在/home/abdullah/Documents/projects/cs50_radio/public/test.php:5中找不到驱动程序 堆栈跟踪: #0/home/abdullah/Documents/projects/cs50_radio/public/test.php(5):PDO-> __ construct('mysql:host = 127 ....')

PHP Fatal error: Uncaught PDOException: could not find driver in /home/abdullah/Documents/projects/cs50_radio/public/test.php:5 Stack trace: #0 /home/abdullah/Documents/projects/cs50_radio/public/test.php(5): PDO->__construct('mysql:host=127....')

PDO已启用并安装.我检查了phpinfo(),但找不到错误.

PDO is enabled and installed. I checked phpinfo(), but I can't figure out the error.

这是我用于连接的代码:

Here is my code used to connect:

<?php
    $user = "root";
    $pass = "root";

    $dbh = new PDO("mysql:host=127.0.0.1;dbname=radio;port=3306", $user, $pass);
    //$dbh->query('INSERT INTO users (name) VALUES ("abdullah")');
    $dbh = null;
?>

我的项目文件夹是否应该包含其他驱动程序或文件?还是我的代码中缺少什么?

Should my project folder contain any additional drivers or files? Or am I missing something in my code?

推荐答案

要使用其他驱动程序,您需要安装它们.在Windows上,您只需取消注释php.ini中的一行:

To use different drivers you need to install them. On Windows you simply uncomment a line in php.ini:

extension=php_pdo_mysql.dll

在Linux上,您可以使用软件包管理器安装扩展程序:

On Linux you install the extension with the package manager:

sudo apt install php7.1-mysql

这篇关于PHP致命错误:未捕获的PDOException:找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆