Use a .ini file to manage your database connection so you can abstract the database type and connection info, in your php apps
The dot ini file
First create a .ini file with the information about your database, like this:
host = localhost name = dbname user = db_username pass = p4ssW0rd type = mysql
The parameter "Type" is optional, but you can use it to make your application be independent of the database, using for example, the PDO library.
Read the file - parseinifile($file) function
To read the config file into your Class, or connection file with the db, use the php function parseinifile($file) passing the path to config file as parameter
// read the .ini file and create an associative array $db = parse_ini_file("path/to/config-file.ini"); /* now we can use the info in that file to create the appropriate, string connection, based on type, or just using the other info */ $user = $db['user']; $pass = $db['pass']; $name = $db['name']; $host = $db['host']; $type = $db['type'];
That's it! Now we got a config file to handle with info about the database. If we needed to change de database type, or user, just change that configuration file and it's done.