0

I am trying to use bake with cakephp. I have gotten to the cake welcome screen below:

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)

I type in C and it asks me about my database configuration:

Bake Controller
Path: /Users/philip7899/Desktop/Philips Server 2/blog/app/Controller/
---------------------------------------------------------------
Use Database Config: (default/test) 
[default] > 

I press enter to confirm using the "default" database configuration. I have pasted it below:

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => 'root',
    'database' => 'cakephp_blog',
    'prefix' => '',

    //'encoding' => 'utf8',
);

I then receive the following errors:

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}

I have spent the past several hours searching the internet and trying to figure this out and I haven't been able to fix it. I know the database configuration is working because the website itself is functioning perfectly. How can I get cake to work in the console and let me proceed? Thanks.

Philip7899
  • 4,599
  • 4
  • 55
  • 114
  • First I have to comment that you are using a Release Candidate version of PHP 2.3.0, when 2.3 branch is already in 2.3.10. Let that aside, since you seem to be in windows, how do you have mysql, php and apache installed? – user221931 Sep 10 '13 at 02:46
  • Try 'host' => '127.0.0.1', rather than 'host' => 'localhost', – joshua.paling Sep 10 '13 at 04:56
  • I have Mac and Mamp and I am using php 5.3 i believe. I tried Joshuas suggestion of changing 'host' => '127.0.0.1' but that did not work either. One thing that worked (i think) was typing in "test" when asked for the database configuration (Remember it prompted me to type default or test) and it worked. But i don't understand, since both the "test" db configuration and the "default" db configuration are identical. How can this be? – Philip7899 Sep 10 '13 at 16:31
  • Do you have a centralized install of CakePHP / Are you calling `cake bake` relative to your APP dir? – jtrumbull Feb 24 '15 at 21:44

1 Answers1

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',
);

} you try this on database.php in config folder

krupal patel
  • 31
  • 1
  • 11