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

即使在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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog