Image courtesy of ddpavumba at FreeDigitalPhotos.net

It is recommended that you do not include database connection details in your scripts, so where exactly do you store them?

Luckily, PHP has the handy function parse_ini_file() specifically for this task.

From php.net:

parse_ini_file ( string $filename [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )

The $process_sections parameter allows you to set section headings which then results in an associative array being returned.

Simply create an ini file – I called mine db.ini

Then, in your code – I am using it in my Auth class:

 

Leave a Reply