Search code examples
phpmysqlcakephpappfog

MissingConnectionException running CakePHP through mysql tunnel on AppFog


while my tunnel is connected (af tunnel) I'm trying to run a cakephp console app that would connect to my mysql database (through the tunnel).

I have this in my database config:

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => '11111111ZQyI',
    'password' => '11111111111MR',
    'database' => '111111111111115bc',
    'port' => '10000',
    'prefix' => '',
    //'encoding' => 'utf8',
);

I would get this error message:

Error: exception 'MissingConnectionException' with message 
'Database connection "Mysql" is     missing, or could not be 
created.' in /.../lib/Cake/Model/Datasource/Database/Mysql.php:161
Stack trace:
#0 /..../lib/Cake/Model/Datasource/DboSource.php(262): Mysql->connect()

Solution

  • The answer was that I needed to somehow invoke mysql to connect of TCP instead of sockets. Apparently when you use localhost it automatically triggers a Socket connection and if you use 12.0.0.1 it triggers a TCP connection. So this was the solution:

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => '127.0.0.1',
        'login' => '11111111ZQyI',
        'password' => '11111111111MR',
        'database' => '111111111111115bc',
        'port' => '10000',
        'prefix' => '',
        //'encoding' => 'utf8',
    );