当我运行这一行时
$pdo = new \PDO('mysql:host=localhost;dbname=mydata','root', null);
我收到此错误
[Symfony\Component\Debug\Exception\ClassNotFoundException]
Attempted to load class "PDO" from namespace "check\roomsBundle\Command".
Did you forget a "use" statement for another namespace?
我尝试将此行添加到我的 parametrs.yml
database_driver: pdo_pgsql
and
database_driver: pdo_mysql
但我使用 symfony2.8 和 mysql 仍然遇到此错误
class SocketCommand extends ContainerAwareCommand
{
protected function configure()
{
//some code here
}
protected function execute(InputInterface $input, OutputInterface $output)
{
//somecode here
$pdo = new \PDO('mysql:host=localhost;dbname=mydata', 'root', null);
}
最佳答案
似乎您只是没有 PDO 扩展,因为语法是正确的。 在 Ubuntu/Debian 上,您应该能够使用
从 apt 安装必要的 PDO 部分sudo apt-get install php-mysql
或者
apt-get install php5-mysql
在旧仓库上
您还必须在 php.ini 中启用它:extension=pdo_mysql.so
但是如果您有扩展名,您可以尝试添加
use \PDO;
在你的包中
关于php - 尝试从命名空间加载类 "PDO",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111909/