我正在尝试使用cakephp进行烘焙。我已经到了下面的蛋糕欢迎屏幕:
Welcome to CakePHP v2.3.0-RC2 Console
---------------------------------------------------------------
App : app
Path: /Users/philip7899/Desktop/Philips Server 2/blog/app/
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
我输入C并询问我的数据库配置:
Bake Controller
Path: /Users/philip7899/Desktop/Philips Server 2/blog/app/Controller/
---------------------------------------------------------------
Use Database Config: (default/test)
[default] >
我按Enter确认使用“默认”数据库配置。我把它贴在下面:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'root',
'database' => 'cakephp_blog',
'prefix' => '',
//'encoding' => 'utf8',
);
然后我收到以下错误:
Warning Error: PDO::__construct(): [2002] No such file or directory
(trying to connect via unix:///var/mysql/mysql.sock) in
[/Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Model/Datasource/Database/Mysql.php, line 157]
Error: Database connection "Mysql" is missing, or could not be created.
#0 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Model/Datasource/DboSource.php(261): Mysql->connect()
#1 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)
#2 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Command/Task/ModelTask.php(903): ConnectionManager::getDataSource('default')
#3 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Command/Task/ControllerTask.php(396): ModelTask->getAllTables('default')
#4 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Command/Task/ControllerTask.php(419): ControllerTask->listAll(NULL)
#5 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Command/Task/ControllerTask.php(136): ControllerTask->getName()
#6 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Command/Task/ControllerTask.php(61): ControllerTask->_interactive()
#7 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Command/BakeShell.php(113): ControllerTask->execute()
#8 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/Shell.php(391): BakeShell->main()
#9 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/ShellDispatcher.php(199): Shell->runCommand(NULL, Array)
#10 /Users/philip7899/Desktop/Philips Server 2/blog/lib/Cake/Console/ShellDispatcher.php(67): ShellDispatcher->dispatch()
#11 /Users/philip7899/Desktop/Philips Server 2/blog/app/Console/cake.php(33): ShellDispatcher::run(Array)
#12 {main}
我花了几个小时在互联网上搜索并尝试解决这个问题,但我无法解决这个问题。我知道数据库配置正在运行,因为网站本身运行正常。我怎样才能让蛋糕在控制台中工作并让我继续?感谢。
答案 0 :(得分:0)
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'admin',// your password
'database' => 'gps',
'prefix' => '',
//'encoding' => 'utf8',
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'test_database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
} 你在config文件夹
中的database.php上试试这个