Connecting to your database in Zend Developer Cloud (Stupid Easy Remix)

Leave a comment

Connecting to the database in the Zend Developer Cloud is quite easy.  You just need the container name, database name, username and password.  But what if you changed containers or your password?

If you want to make your application able to be easily moved between containers (and you should) here is a stupid easy way to do it.  Use get_cfg_var().

For example

1
2
3
4
5
6
7
8
9
10
11
$dsn = sprintf(
	'mysql:dbname=%s;host=%s',
	get_cfg_var('zend_developer_cloud.db.name'),
	get_cfg_var('zend_developer_cloud.db.host')
);
 
$db = new PDO(
	$dsn,
	get_cfg_var('zend_developer_cloud.db.username'),
	get_cfg_var('zend_developer_cloud.db.password')
);

Easy.

Leave a Reply

Your email address will not be published. Required fields are marked *