I am using Laravel with HHVM.
我正在使用Laravel和HHVM。
MySQL is working in normal controller functions.
MySQL正在使用普通的控制器功能。
But whenever from Commands (artisan), DB connection of MySQL (PDO) is initialised, then error comes of "could not find driver".
但无论何时从Commands(工匠),MySQL(PDO)的DB连接被初始化,然后错误来自“找不到驱动程序”。
Also I have tried writing connection initialisation from Controller function and calling it from Command still same error comes.
此外,我尝试从Controller函数编写连接初始化并从Command调用它仍然出现相同的错误。
$conn = new \PDO("mysql:host=$servername;dbname=$db_name", $username, $password);
2 个解决方案
#1
I think you have not installed php-mysql driver
我想你还没有安装php-mysql驱动
Try installing by using following command
尝试使用以下命令进行安装
sudo apt-get install php5 php5-mysql
#2
Make sure the PDO mysql driver is enabled.
确保已启用PDO mysql驱动程序。
If you're running debian/ubuntu, you can check like this
如果你正在运行debian / ubuntu,你可以这样检查
$ php -i | grep pdo
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-pdo_mysql.ini, # <-- This line
pdo_mysql
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
And if it's not enabled, you can enable it with:
如果未启用,您可以启用它:
$ php5enmod pdo_mysql
For other operating systems, you'll have to check the documentation.
对于其他操作系统,您必须查看文档。
Don't forget to restart your web server (Apache, or other).
不要忘记重新启动Web服务器(Apache或其他)。
#1
I think you have not installed php-mysql driver
我想你还没有安装php-mysql驱动
Try installing by using following command
尝试使用以下命令进行安装
sudo apt-get install php5 php5-mysql
#2
Make sure the PDO mysql driver is enabled.
确保已启用PDO mysql驱动程序。
If you're running debian/ubuntu, you can check like this
如果你正在运行debian / ubuntu,你可以这样检查
$ php -i | grep pdo
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-pdo_mysql.ini, # <-- This line
pdo_mysql
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
And if it's not enabled, you can enable it with:
如果未启用,您可以启用它:
$ php5enmod pdo_mysql
For other operating systems, you'll have to check the documentation.
对于其他操作系统,您必须查看文档。
Don't forget to restart your web server (Apache, or other).
不要忘记重新启动Web服务器(Apache或其他)。