by Kevin Schroeder | 3:06 pm

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.

Tags:

Comments

No comments yet...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.