PHP 致命错误:找不到“PDO”类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11813381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Fatal error: Class 'PDO' not found
提问by Amanada Smith
PHP Fatal error: Class 'PDO' not found in /home/bd/public_html/app/webroot/Cake/Model/Datasource/Database/Mysql.php on line 177
PHP INFO:
PHP信息:
PDO
PDO support => enabled
PDO drivers => sqlite, sqlite2, mysql
pdo_mysql
PDO Driver for MySQL => enabled
Client API version => 5.5.24
Directive => Local Value => Master Value
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
pdo_sqlite
PDO Driver for SQLite 3.x => enabled
SQLite Library => 3.7.7.1
PHP INI:
PHP INI:
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so
CODE:
代码:
/**
* Check whether the MySQL extension is installed/loaded
*
* @return boolean
*/
public function enabled() {
return in_array('mysql', PDO::getAvailableDrivers());
}
Ideas as to why I'm getting this error?
关于为什么我收到此错误的想法?
PHP 5.3.15 CloudLinux/CentOS 6 CPanel
PHP 5.3.15 CloudLinux/CentOS 6 CPanel
回答by B?o Nam
try
尝试
yum install php-pdo
yum install php-pdo_mysql
service httpd restart
回答by Jo Smo
Try adding use PDO;after your namespace or just before your class or at the top of your PHPfile.
尝试use PDO;在您的命名空间之后或在您的班级之前或在您的PHP文件顶部添加。
回答by Alastair Irvine
This can also happen if there is a php.inifile in the web app's current working directory. If one has been placed there to change certain settings, it will override the global one.
如果php.iniWeb 应用程序的当前工作目录中有文件,也会发生这种情况。如果在那里放置了一个来更改某些设置,它将覆盖全局设置。
To avoid this problem, don't use a php.inifile to change settings; instead you can:
为避免此问题,请不要使用php.ini文件来更改设置;相反,您可以:
回答by Bruno Ribeiro
Ensure they are being called in the php.ini file
确保在 php.ini 文件中调用它们
If the PDO is displayed in the list of currently installed php modules, you will want to check the php.ini file in the relevant folder to ensure they are being called. Somewhere in the php.ini file you should see the following:
如果 PDO 显示在当前安装的 php 模块列表中,您需要检查相关文件夹中的 php.ini 文件以确保它们正在被调用。在 php.ini 文件的某处,您应该看到以下内容:
extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so
If they are not present, simply add the lines above to the bottom of the php.ini file and save it.
如果它们不存在,只需将上面的行添加到 php.ini 文件的底部并保存。
回答by Stephen
What is the full source of the file Mysql.php. Based on the output of the php info list, it sounds like you may be trying to reference a global class from within a namespace.
文件的完整来源是什么Mysql.php。根据 php 信息列表的输出,听起来您可能正在尝试从命名空间中引用全局类。
If the file Mysql.phphas a statement "namespace " in it, use \PDOin place of PDO- this will tell PHP to look for a global class, rather than looking in the local namespace.
如果文件中Mysql.php有一个语句“namespace”,使用\PDO代替PDO- 这将告诉 PHP 查找全局类,而不是查找本地名称空间。
回答by Rust
I had the same problem on GoDaddy. I added the extension=pdo.soto php.ini, still didn't work. And then only one thing came to my mind: Permissions
我在GoDaddy上遇到了同样的问题。我加入了extension=pdo.so到php.ini,仍然没有工作。然后我想到的只有一件事:权限
Before uploading the file, kill all PHP processes(cPanel->PHP Processes).
在上传文件之前,杀死所有 PHP 进程(cPanel->PHP 进程)。
The problem was that with the file permissions, it was set to 0644and was not executable . You need to set the file permission at least 0755.
问题在于,文件权限设置为0644并且不可执行。您至少需要设置文件权限0755。
回答by Hasitha
you can just find-out loaded config file by executing below command,
您可以通过执行以下命令来找出加载的配置文件,
php -i | grep 'php.ini'
Then add below lines to correct php.ini file
然后添加以下行以更正 php.ini 文件
extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so
Then restart web server,
然后重启web服务器,
service httpd restart
回答by Pavel Hájek
回答by Predominant
This error is caused by PDOnot being available to PHP.
此错误是由PDOPHP 不可用引起的。
If you are getting the error on the command line, or not via the same interface your website uses for PHP, you are potentially invoking a different version of PHP, or utlising a different php.iniconfiguration file when checking phpinfo().
如果您在命令行上收到错误,或者不是通过您的网站用于 PHP 的相同界面,您可能会调用不同版本的 PHP,或者php.ini在检查phpinfo().
Ensure PDO is loaded, and the PDO drivers for your database are also loaded.
确保 PDO 已加载,并且您的数据库的 PDO 驱动程序也已加载。
回答by Wells
Its a Little Late but I found the same problem and i fixed it by a "\" in front of PDO
它有点晚了,但我发现了同样的问题,我在 PDO 前面用“\”修复了它
public function enabled() {
return in_array('mysql', \PDO::getAvailableDrivers());
}


