Welcome Guest, Not a member yet? Register   Sign In
DB Cache here? yes or no?
#1

[eluser]mvdg27[/eluser]
Hi guys,

We are currenty working on a CMS system and going through all the code, to see where we can improve stuff (speed, code-style, server load etc.).

We now came across this auto-loaded library we made to use different databases for different users on the same application. Now the question is whether we could use database caching on this feature? Since the database login information is not likely to change often ..

Or is it safe to store the database info in a session? Preventing from making a query for each user action. I'm using the native session lib for sessions by the way, since the CI lib doesn't work well with Ajax request, and our CMS is build mainly on Ajax technology.

Code:
<?php
class Db_connect {

    var $CI;    

    function Db_connect() {    
        // Reference to CodeIgniter instance
        $this->CI =& get_instance();

        if($this->CI->logincheck->is_logged_in()) {
            // should we do database caching here?        
            $login_db = $this->CI->load->database('login', true);
            $login_db->where('users.id', $this->CI->session->userdata('user_id'));
            $login_db->where('sites.id', $this->CI->session->userdata('site_id'));
            $login_db->join('sites', 'users.site_id = sites.id');  
            $query = $login_db->get('users');
            $db_data = $query->first_row();
                        
            $db['hostname'] = "localhost";

            $db['username'] = $db_data->db_username;

            $db['password'] = $db_data->db_password;

            $db['database'] = $db_data->database;

            $db['dbdriver'] = "mysql";

            $db['dbprefix'] = "";

            $db['pconnect'] = TRUE;

            $db['db_debug'] = TRUE;

            $db['cache_on'] = FALSE;

            $db['cachedir'] = "";

            $db['char_set'] = "utf8";

            $db['dbcollat'] = "utf8_general_ci";
            $this->CI->load->database($db);
        }
    }
}
?>

Thanks in advance for the feedback.




Theme © iAndrew 2016 - Forum software by © MyBB