1

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?

user1121487
  • 2,662
  • 8
  • 42
  • 63

3 Answers3

1

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] => ""
)*/
Fred Wuerges
  • 1,965
  • 2
  • 21
  • 42
0

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

Elby
  • 1,624
  • 3
  • 23
  • 42
0

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.

user1121487
  • 2,662
  • 8
  • 42
  • 63