蛋糕烘焙控制台错误:数据库连接丢失

时间:2012-04-28 09:43:59

标签: cakephp xampp cakephp-2.0 php ubuntu-11.10

我使用控制台烘焙了一个应用程序,并且从URL看起来一切正常。但是当我想在应用程序文件夹中烘焙模型时,我收到一个错误:

        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}

这就是我在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',
        );
    }

我的php --ini返回:

        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

虽然phpinfo()给了我这条道路:

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

上述两项产出是否存在矛盾?我的意思是php --ini应该输出xampp的php.ini而不是另一个,我怎么能指向xampp的php.ini?我尝试通过改变.bashrc这条线来改变它,没有任何帮助,

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

我尝试将此行添加到database.configuration文件中:             'port'=&gt; '/opt/lampp/var/mysql/mysql.sock' 但它没有帮助。

我确实发现了一些类似的问题,但是对于ubuntu来说,它们要么是针对mac osx的。

3 个答案:

答案 0 :(得分:1)

帮助(更多) OSX (XAMPP)用户:

只需将以下内容添加到app/Config/database.php db config数组中:

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

答案 1 :(得分:0)

您需要启用pdo_mysql扩展,它可能已经为您的Web环境启用了,但是ubuntu将cli和web的php.ini配置分开。

所以,你只需要为cli

启用扩展名

答案 2 :(得分:0)

帮助 OSX 用户:

只需将以下内容添加到/app/Config/database.php配置变量:

  

'unix_socket'=&gt; '/Applications/MAMP/tmp/mysql/mysql.sock'