Configuration data stored in the database

I could bark completely on the wrong tree, so forgive me if this is not at all the way I should be doing something.

I have a configuration table in my database that contains configuration data for my site. I want to load this data into a config.php file for a code igniter?

Is this something I have to do, or is it completely wrong?

If I put the database call at the beginning of the config.php file, will it be called every time someone loads the site or only the first time?

Sorry if that sounds totally stupid, I'm a little confused.

Edit

I do not mean database data, for example, I want to store something like the number of messages that should be displayed on the page. The created script should be used on more than one server, for example, the number of posts on the page should be editable. I could have caused this to load into the session, but I thought loading it as a constant *? in a config file would be a better idea.

+5
source share
3 answers

, , . $this->model_name->function_name($db_column); $db_column , , .

:
http://codeigniter.com/user_guide/libraries/config.html

+7

:

-, :

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

.

class Prefs extends CI_Model
{
    function __construct()
    {
        parent::__construct();      
        $pre = array();
        $CI = &get_instance();

        if ($this->config->item("useDatabaseConfig")) {
            $pr = $this->db->get("settings")->result();     
            foreach($pr as $p)
            {
                $pre[addslashes($p->key)] = addslashes($p->value);
            }       
        }
        else
        {
            $pre = (object) $CI->config->config;
        }   
        $CI->pref = (object) $pre;      
    } 
}
  • .
  • config/config.php, ( , ): $config["useDatabaseConfig"] = true;

"" "" "".

. , , , config/*. Php.

, $config["useDatabaseConfig"] ( .)

CI, , .
: $this->pref->sess_cookie_name

+10

This is what you should not do. A database call is made every time a query is executed, and you cannot store the database credentials in the database itself.

0
source

All Articles