SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Config in MYSQL

  1. #1
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Config in MYSQL

    I have lots of config settings in an array

    PHP Code:
    $config["cache"] = TRUE;
    //votes
    $config['vote']['status'] = TRUE
    $config['vote']['guestvote'] = FALSE
    This started out as a good plan to organise and give configuration options to the rest of the pages.
    Now I want to put these into MYSQL, which I could do if they where all plain and simple:
    PHP Code:
    $config["cache"] = TRUE
    but i have 2 and even 3 tear array as config
    PHP Code:
    $config['vote']['guestvote'] = FALSE;
    $config['main']['title']["item_id"] = "Newist"
    Apart from going trough every page and edit conif vars is their a way to output this nicely in from mysql.
    I was thinking giving Field names like cache and two tear vote|guestvote

    Help is MUCH appreciated, as ive dugg myself into a hole..I did not know i had a spade.
    ----------------
    This is v1 of my cms, and advice or tips on config much appretiated.

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Location
    Winnipeg
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have little choice but to refactor your code, MySQL is a relational database, so hierarchy is not easily expressed; albeit it's still possible.

    I would suggest going with a table like:

    Code:
    pkid, name, value
    If you want hierarchy, add a field, like

    Code:
    pkid, rootid, name, value
    IMHO however, storing config values in a DB is a bad practice. Config files are easy to update and very portable. Not only that but if your DB goes down or similar your application will probably completely fall over.

    When you start installing the application on client servers and they give you FTP but not CPanel or MySQL details, and the issue is being caused due to config issues, your also screwed.
    The only constant in software is change itself

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The simplest way is not to store config settings in a database.

    Use an ini file, or include files with settings as they are needed and keep the arrays as arrays.

    ini_get

  4. #4
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at this link.

  5. #5
    SitePoint Zealot NuWeb's Avatar
    Join Date
    Aug 2005
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PCSpectra, thank you for the post that is the solution to my problem. Although after reading the link posted by simshaun regarding .ini then that seems the most efficient method of reading settings.

    Would remove the need to cache the config.php serialise/unserliaze ... Thanks for this Cups & simshaun great help!

  6. #6
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you do use .ini, be absolutely sure to set it up outside of the webroot or where it can not be read from the browser.

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Logic_earth also came up with a nice idea in this old post (#8).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •