1

我正在通过烘焙命令在 CakePHP 中烘焙模型

 ./cake bake model all

我已经正确配置了 database.php。

    public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => '',
    'database' => 'mydb',
    'prefix' => '',
    //'encoding' => 'utf8',
);

烘焙模型时出现此错误

#0 /opt/lampp/htdocs/febrics/lib/Cake/Model/Datasource/DboSource.php(262): Mysql->connect()
#1 /opt/lampp/htdocs/febrics/lib/Cake/Model/ConnectionManager.php(107): DboSource->__construct(Array)
#2 /opt/lampp/htdocs/febrics/lib/Cake/Console/Command/Task/ModelTask.php(900): ConnectionManager::getDataSource('default')
#3 /opt/lampp/htdocs/febrics/lib/Cake/Console/Command/Task/ModelTask.php(837): ModelTask->getAllTables('default')
#4 /opt/lampp/htdocs/febrics/lib/Cake/Console/Command/Task/ModelTask.php(123): ModelTask->listAll('default', false)
#5 /opt/lampp/htdocs/febrics/lib/Cake/Console/Command/Task/ModelTask.php(102): ModelTask->all()
#6 /opt/lampp/htdocs/febrics/lib/Cake/Console/Shell.php(389): ModelTask->execute()
#7 /opt/lampp/htdocs/febrics/lib/Cake/Console/Shell.php(386): Shell->runCommand('execute', Array)
#8 /opt/lampp/htdocs/febrics/lib/Cake/Console/ShellDispatcher.php(202): Shell->runCommand('model', Array)
#9 /opt/lampp/htdocs/febrics/lib/Cake/Console/ShellDispatcher.php(68): ShellDispatcher->dispatch()
#10 /opt/lampp/htdocs/febrics/app/Console/cake.php(37): ShellDispatcher::run(Array)
#11 {main}

请让我知道我错在哪里。
谢谢

4

2 回答 2

2

将本地主机更改为 127.0.0.1

由于某种原因,在使用 localhost 时,它在烘焙时无法通过命令行工作。

于 2016-10-09T16:49:57.380 回答
1

当我们基于 database.php 文件中的 HOST 切换配置时,我们通常会遇到这个问题。

您是否试图在任何地方切换数据库?请注意,$_SERVER['HTTP_HOST'] 在命令行中不可用。

于 2013-10-01T22:42:44.090 回答