tutak
tutak

Reputation: 1098

cake bake console error:Database connection missing

I baked an application using console and from URL everything seems ok. But when i want to bake a model inside the application folder, I get an error:

        Error: Database connection "Mysql" is missing, or could not be created.
        #0 /opt/lampp/cake/lib/Cake/Model/ConnectionManager.php(98): DboSource->__construct(Array)
        #1 /opt/lampp/cake/lib/Cake/Console/Command/Task/ModelTask.php(837): ConnectionManager::getDataSource('default')
        #2 /opt/lampp/cake/lib/Cake/Console/Command/Task/ModelTask.php(782): ModelTask->getAllTables(NULL)
        #3 /opt/lampp/cake/lib/Cake/Console/Command/Task/ModelTask.php(863): ModelTask->listAll(NULL)
        #4 /opt/lampp/cake/lib/Cake/Console/Command/Task/ModelTask.php(186): ModelTask->getName()
        #5 /opt/lampp/cake/lib/Cake/Console/Command/Task/ModelTask.php(84): ModelTask->_interactive()
        #6 /opt/lampp/cake/lib/Cake/Console/Command/BakeShell.php(102): ModelTask->execute()
        #7 /opt/lampp/cake/lib/Cake/Console/Shell.php(375): BakeShell->main()
        #8 /opt/lampp/cake/lib/Cake/Console/ShellDispatcher.php(177): Shell->runCommand(NULL, Array)
        #9 /opt/lampp/cake/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
        #10 /opt/lampp/cake/lib/Cake/Console/cake.php(24): ShellDispatcher::run(Array)
        #11 {main}

This is what I have in my opt/lampp/htdocs/cakapp/Confg/database.php

 <?php
    class DATABASE_CONFIG {

        public $default = array(
            'datasource' => 'Database/Mysql',
            'persistent' => false,
            'host' => '127.0.0.1',
            'login' => 'root',
            'password' => 'alpha',
            'database' => 'cakedb',
        );
    }

my php --ini return:

        Configuration File (php.ini) Path: /etc/php5/cli
        Loaded Configuration File:         /etc/php5/cli/php.ini
        Scan for additional .ini files in: /etc/php5/cli/conf.d
       Additional .ini files parsed:      /etc/php5/cli/conf.d/pdo.ini

while phpinfo() give me this path:

        Configuration File (php.ini) Path: /opt/lampp/etc
        Loaded Configuration File :/opt/lampp/etc/php.ini 

Isnt there a contradiction in the above two outputs? I mean php --ini is supposed to outputting the php.ini of the xampp not the other one, how can i make it point at the xampp's php.ini? I tried to change it by changing .bashrc with this line, no help ofcourse

 export PATH=/opt/lampp/bin:$PATH

I tried to add this line to the database.configuration file: 'port' => '/opt/lampp/var/mysql/mysql.sock' But it didnt help.

I did find some similar problems but they are either for windows for mac osx nothing for ubuntu.

Upvotes: 0

Views: 3270

Answers (3)

ala_747
ala_747

Reputation: 611

To help (more) OSX (XAMPP) users:

just add the following to your app/Config/database.php db config array:

'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'

Upvotes: 1

zvaehn
zvaehn

Reputation: 91

To help OSX users:

just add the following to your /app/Config/database.php Config-Variable:

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'

Upvotes: 0

You need to enable the pdo_mysql extension, it might be already enabled for your web environment, but ubuntu separates the php.ini configuration for cli and web.

So, you just need to enable the extension for cli

Upvotes: 0

Related Questions