在 yii2 中迁移时出现异常“找不到驱动程序"
这是我的堆栈跟踪:
Exception 'yiidbException' with message 'could not find driver'
in /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Connection.php:534
#0 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Connection.php(836): yiidbConnection->open()
#1 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Connection.php(823): yiidbConnection->getMasterPdo()
#2 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Command.php(208): yiidbConnection->getSlavePdo()
#3 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Command.php(816): yiidbCommand->prepare(true)
#4 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Command.php(350): yiidbCommand->queryInternal('fetchAll', NULL)
#5 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/mysql/Schema.php(198): yiidbCommand->queryAll()
#6 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/mysql/Schema.php(97): yiidbmysqlSchema->findColumns(Object(yiidbTableSchema))
#7 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/db/Schema.php(140): yiidbmysqlSchema->loadTableSchema('migration')
#8 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/console/controllers/MigrateController.php(121): yiidbSchema->getTableSchema('{{%migration}}', true)
#9 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(610): yiiconsolecontrollersMigrateController->getMigrationHistory(NULL)
#10 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(102): yiiconsolecontrollersBaseMigrateController->getNewMigrations()
#11 [internal function]: yiiconsolecontrollersBaseMigrateController->actionUp(0)
#12 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#13 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/base/Controller.php(151): yiiaseInlineAction->runWithParams(Array)
#14 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/console/Controller.php(91): yiiaseController->runAction('', Array)
#15 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/base/Module.php(455): yiiconsoleController->runAction('', Array)
#16 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/console/Application.php(161): yiiaseModule->runAction('migrate', Array)
#17 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/console/Application.php(137): yiiconsoleApplication->runAction('migrate', Array)
#18 /opt/lampp/htdocs/advanced/vendor/yiisoft/yii2/base/Application.php(375): yiiconsoleApplication->handleRequest(Object(yiiconsoleRequest))
#19 /opt/lampp/htdocs/advanced/yii(31): yiiaseApplication->run()
#20 {main}
我是 yii2 的新手.我在 advaced/common/config/main-local.php
中添加了数据库名称、用户名.使用 xampp 网络服务器,php 版本为 5.6.8,并且还启用了 PDO.
I am new to yii2. I have added database name,username in advaced/common/config/main-local.php
. Using xampp webserver and version of php is 5.6.8 and PDO is also enabled.
这是我的数据库配置.
'db' => [
'class' => 'yiidbConnection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
推荐答案
在 Yii2
最有可能是你的系统配置.如果你使用的是像这样的包MAMP、XAMPP 或其他,您可能需要将localhost"更改为db.php 配置文件中的127.0.0.1".另外如果你在Linux 你可能需要安装一些其他的附加包,比如php5-mysql 之类的东西."
"Most likely it is your system config. If you are using packages like MAMP, XAMPP or other, you may need to change "localhost" to "127.0.0.1" in your db.php configuration file. Also if you are on Linux you may need to install some other additional packages like php5-mysql and stuff like that."
相关文章