我使用 Ubuntu 22.04 和 php 7.4。我尝试使用 apache2 为我的网站提供虚拟主机。可以打开登录页面,在我们插入帐户后,错误显示 could not find driver on /var/www/website/app/models/PDODb.php on line229 that line is
$this->pdo = new PDO($connectionString, $this->connectionParams['username'], $this->connectionParams['password'], $options);
我已经取消注释了 php.ini 上的 extension=pdo_mysql 并且已经重新启动了 apache2。
使用 php -i | grep pdo_mysql会导致这个
/etc/php/7.4/cli/conf.d/20-pdo_mysql.ini, API Extensions => mysqli,pdo_mysql pdo_mysql pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
这是我的 website.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/website
DirectoryIndex /index.php index.php /index.html index.html
<Directory "/var/www/website">
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
这是我用于连接数据库的 config.php 定义(“DB_HOST”,“127.0.0.1”);
define("DB_USERNAME", "root");
define("DB_PASSWORD", "root123");
define("DB_NAME", "db_website");
define("DB_TYPE", "mysqli");
define("DB_PORT", "");
define("DB_CHARSET", "utf8");
我已经尝试遵循这个问题,但它仍然给我相同的结果。我该怎么办?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
只需将
define("DB_TYPE", "mysqli");更改为define("DB_TYPE", "mysql");因为我只得到了 mysql_pdo