2 responses to “Php: How To Store System Configurations On A Database And Use Them As Constants?”

  1. wefixcom

    Make a settings file and put this in it (settings.php)
    < ?php
    $cfg_server="serveraddress";
    $cfg_database="dbname";
    $cfg_username="username";
    $cfg_password="dbpassword";
    ?>
    Now just put this in any file that needs to access the database
    include (“settings.php”);
    $link = mysql_connect(“$cfg_server”,”$cfg_userna…
    or die(“error “);
    mysql_select_db (“$cfg_database”, $link)
    or die(“error “);

  2. robotchi…

    Define a table with two columns:
    CREATE TABLE IF NOT EXISTS myconfigtable
    (
    valueName varchar(50) collate utf8_unicode_ci NOT NULL
    value varchar(50) collate utf8_unicode_ci NOT NULL
    );
    Then, fetch the necessary records from the database by simple SQL:
    SELECT valueName, value
    FROM myconfigtable
    WHERE valueName = “myconfigparameter1″
    ETA: The other option is to place a PHP file that is included within your web pages into a directory where it can be modified by using the fopen(), readfile(), writefile() functions already available in PHP