例外' yii \ db \ Exception'有消息'无法找到驱动程序'

时间:2017-10-18 17:58:40

标签: php yii2 xampp yii2-advanced-app linuxmint

我刚刚在linux mint 18.2上安装了yii2.0高级版,使用XAMPP for Linux 7.0.23,我的php yii migrate / up命令不起作用。它显示:

with message 'could not find driver'

in /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Connection.php:584

我用谷歌搜索了它,我得到了几个结果。在那里,我读了'使用php -m命令&#39 ;;你会发现你的系统使用过哪个php。但是我不知道运行命令后预期的输出是什么。

 with message 'could not find driver'

in /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Connection.php:584

Stack trace:
#0 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Connection.php(928): yii\db\Connection->open()
#1 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Connection.php(915): yii\db\Connection->getMasterPdo()
#2 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Command.php(219): yii\db\Connection->getSlavePdo()
#3 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Command.php(910): yii\db\Command->prepare(true)
#4 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Command.php(362): yii\db\Command->queryInternal('fetchAll', NULL)
#5 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/mysql/Schema.php(199): yii\db\Command->queryAll()
#6 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/mysql/Schema.php(98): yii\db\mysql\Schema->findColumns(Object(yii\db\TableSchema))
#7 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/db/Schema.php(152): yii\db\mysql\Schema->loadTableSchema('migration')
#8 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/console/controllers/MigrateController.php(194): yii\db\Schema->getTableSchema('{{%migration}}', true)
#9 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(814): yii\console\controllers\MigrateController->getMigrationHistory(NULL)
#10 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(155): yii\console\controllers\BaseMigrateController->getNewMigrations()
#11 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#12 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#13 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#14 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/console/Controller.php(128): yii\base\Controller->runAction('up', Array)
#15 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/base/Module.php(523): yii\console\Controller->runAction('up', Array)
#16 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/up', Array)
#17 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('migrate/up', Array)
#18 /opt/lampp/htdocs/yii/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#19 /opt/lampp/htdocs/yii/yii(27): yii\base\Application->run()
#20 {main}

2 个答案:

答案 0 :(得分:1)

您需要安装pdo_mysql模块。

sudo apt-get install php-mysql

之后检查phpinfo();

答案 1 :(得分:0)

我也遇到了这个错误。 pdo_mysql 驱动程序已安装并显示在 phpinfo() 中,Web 应用程序运行良好,但从命令行找不到驱动程序。解决办法是提供php版本

cd /var/www/html/project_folder
php7.1 application/yii.php controller/method