PhpCloud Logo Official Logo

PhpCloud quick note on DSN

Cloud is the new magical word of these 2 years and a lot of  solutions are moving to Clouds which basically is a set of web-apps hosted on the internet. There have been a few php-cloud solutions as well, most of them commercial and Zend (the company behind PHP), has lately launched the phpcloud.com.

I started testing a little bit the phpcloud.com with the ZendFramework 2 and immediately run in an error while configuring the MySQL Connection.

return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname={MYCONTAINER};hostname={MYCONTAINER}-db.my.phpcloud.com',
'username' => '{MYCONTAINER}',
'password' => '12345678'
),
),
);

I was getting a lot of “cannot connect to local mysql instance”.

Apparently there is an easier way of creating the DSN and username/password connection with the phpcloud:

 

$dsn = sprintf(
                'mysql:dbname=%s;host=%s',
                get_cfg_var('zend_developer_cloud.db.name'),
                get_cfg_var('zend_developer_cloud.db.host')
);

return array(
                'db' => array(
                                'driver' => 'Pdo',
                                'dsn' => $dsn,
                                'username' => get_cfg_var('zend_developer_cloud.db.username'),
                                'password' => get_cfg_var('zend_developer_cloud.db.password')
                ),
);

Leave a Reply