Question

I've made an install script for mysql tables. I want the user to set the database configurations. The configurations for mysql is hard coded in a PHP class as public variables.

What would be best practice for creating and storing the config data on install?

Was it helpful?

Solution 3

Use PHP fwrite() to create content to an empty PHP-file. Content is defined constants of users input. Use these constants to set value to the Database configuration file.

OTHER TIPS

I recommend using a .ini file. Example:

database.config.ini:

host = "localhost"
db = "test"
user = "root"
pass = ""

To load config:

$config = parse_ini_file('database.config.ini');
print_r($config);

/*Array
(
    [host] => "localhost"
    [db] => "test"
    [user] => "root"
    [pass] => ""
)*/

Create a form for accept config data, during the process these content to write to a file or a xml . Then read from file config datas

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top