PHP 致命错误:类“PDO”未找到
我有这个 PHP 函数,它一直工作得很好,直到我重新安装了我的开发系统:
function connectDB($database, $username, $password) {
$DSN = "mysql:host=localhost;dbname=$database";
try {
$DBH = new PDO($DSN, $username, $password); <--- LINE 10
return $DBH;
}
catch(PDOException $e) {
die("Could not connect to the database.\n");
}
}
我收到错误:
PHP Fatal error: Class 'PDO' not found in /var/www/im/tools.php on line 10
我检查了 phpinfo() 并且 PDO 已启用:
PDO 驱动程序:mysql
PDO Driver for MySQL 版本:
5.1.54有趣的是,与 MYSQL 数据库的交互是可以的,但是我在调试时仍然收到错误。
我对这个错误很困惑!我的系统是 Ubuntu 11.04 + NGINX + PHP 5.3
有什么技巧可以摆脱它吗?谢谢!
I have this PHP function which has been working very well until i reinstalled my dev system:
function connectDB($database, $username, $password) {
$DSN = "mysql:host=localhost;dbname=$database";
try {
$DBH = new PDO($DSN, $username, $password); <--- LINE 10
return $DBH;
}
catch(PDOException $e) {
die("Could not connect to the database.\n");
}
}
And i'm getting the error:
PHP Fatal error: Class 'PDO' not found in /var/www/im/tools.php on line 10
I checked phpinfo() and PDO is enabled:
PDO drivers : mysql
PDO Driver for MySQL version: 5.1.54
The interesting thing is that the interaction with th MYSQL database is ok, but i'm still getting the error when debugging.
I'm puzzled about this error! My system is Ubuntu 11.04 + NGINX + PHP 5.3
Any tip to get rid of it? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您使用命名空间代码吗?也许你需要使用 \PDO 类?
Are you using namespaced code? Maybe you need to use \PDO class then?
如果 Web 应用程序的当前工作目录中有 php.ini 文件,也可能会发生这种情况。如果在那里放置了一个来更改某些设置,它将覆盖全局设置。
为了避免这个问题,不要使用 php.ini 更改设置;相反,请在 vhost 声明或带有“php_flag”的 .htaccess 文件中执行此操作。
另请参阅 PHP 致命错误:未找到“PDO”类
This can also happen if there is a php.ini file in the web app's current working directory. If one has been placed there to change certain settings, it will override the global one.
To avoid this problem, don't use a php.ini change settings; instead, do this in the vhost declaration or a .htaccess file with 'php_flag'.
See also PHP Fatal error: Class 'PDO' not found
尝试
try