I am baking Models in CakePHP through baking command

 ./cake bake model all

I have configure database.php correctly.

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

I am getting this error while baking Models

#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}

Please let me know where I am wrong.
THANKS

有帮助吗?

解决方案

Change localhost to 127.0.0.1

For some reason when using localhost it doesn't work via the command line while baking.

其他提示

We normally run into this problem when we are switching the configurations based on the HOST in the database.php file.

Are you trying to switch the database anywhere? Note that $_SERVER['HTTP_HOST'] is not available from command-line.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top