douxuanou2787 2019-01-14 05:26
浏览 133
已采纳

即使在Web服务器上启用PDO,PDO也会失败

I moved to a new hard drive, and copied everything necessary to the best of my knowledge. I try to load any page that requires my PDO Database object and it crashes.

This is the error:

Fatal error: Uncaught Error: Class 'PDO' not found in /var/www/the_website.net/config/DB.php:20 Stack trace:
#0 /var/www/the_website.net/public_html/index.php(16): DB->__construct()
#1 {main} thrown in /var/www/the_website.net/config/DB.php on line 20

This is the line (and few surrounding lines) in question in DB.php:

public function __construct($username='username', $password='supersecretpassword', $host='localhost', $dbname='database', $options=[])
{
    $this->isConnected = true;
    try {
        $this->db_data = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8",$username, $password, $options);
        $this->db_data->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->db_data->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        throw new Exception($e->getMessage());
    }
}

It's just the creation of the object.

Here are my enabled modules in /etc/php/7.2/apache2/php.ini (I just did them all because nothing was working anyway):

extension=openssl
extension=pdo_firebird
extension=pdo.so
extension=pdo_mysql
extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite

Here is the result of php -m

root@HAL4:/etc/php/7.2/apache2# php -m
[PHP Modules]
calendar
Core
ctype
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO <-- Still doesn't work
pdo_mysql <-- Nope. Still not working.
Phar
posix
readline
Reflection
session
shmop
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

I have run phpenmod for both modules.

My former hard drive was running php 7.0. Now I'm running php 7.2.

Running <?php phpinfo(); ?> in a test page tells me:

Configuration File (php.ini) Path   /etc/php/7.0/apache2
Loaded Configuration File   (none)
Scan this dir for additional .ini files /etc/php/7.0/apache2/conf.d
Additional .ini files parsed    (none)

Update I removed the php7.0 modules completely from /usr/lib/apache2/ so now everything is php7.2. My phpinfo() file displays the correct paths:

Configuration File (php.ini) Path   /etc/php/7.2/apache2
Loaded Configuration File   /etc/php/7.2/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.2/apache2/conf.d

Still getting the Class'PDO' not found error, however.

What else can I check? Why are they not loading?

  • 写回答

1条回答 默认 最新

  • dstnlhhv791576 2019-01-14 18:41
    关注

    I purged PHP, and started over. I did the exact same thing I did before and followed the errors. I kept getting the same fatal error, until I did:

    apt install php7.2-mysql
    

    My problem was resolved.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色