Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Error using multiple database using CodeIgniter
Old 01-23-2010, 05:56 PM Error using multiple database using CodeIgniter
Novice Talker

Posts: 10
Name: adi sembiring
Trades: 0
Hi ..., I'm trying to implement mutiple database in CI. My code Is here:

PHP Code:
//database.php
    
$active_group "default";
    
$active_record TRUE;
    
    
$db['default']['hostname'] = "localhost";
    
$db['default']['username'] = "root";
    
$db['default']['password'] = "root";
    
$db['default']['database'] = "ravelex";
    
$db['default']['dbdriver'] = "mysql";
    
$db['default']['dbprefix'] = "rvx_";
    
$db['default']['pconnect'] = TRUE;
    
$db['default']['db_debug'] = TRUE;
    
$db['default']['cache_on'] = FALSE;
    
$db['default']['cachedir'] = "";
    
$db['default']['char_set'] = "utf8";
    
$db['default']['dbcollat'] = "utf8_general_ci";
    
    
$db['smf']['hostname'] = "localhost";
    
$db['smf']['username'] = "root";
    
$db['smf']['password'] = "root";
    
$db['smf']['database'] = "smf";
    
$db['smf']['dbdriver'] = "mysql";
    
$db['smf']['dbprefix'] = "smf_";
    
$db['smf']['pconnect'] = TRUE;
    
$db['smf']['db_debug'] = TRUE;
    
$db['smf']['cache_on'] = FALSE;
    
$db['smf']['cachedir'] = "";
    
$db['smf']['char_set'] = "utf8";
    
$db['smf']['dbcollat'] = "utf8_general_ci"
The model is

PHP Code:
//user_model.php
    
class user_model extends Model {
        private 
$ravelex_db;
        function 
user_model() {
            
parent::Model();
            
$this->ravelex_db $this->load->database('default'TRUE);
        }
        
        function 
find_all() {
            
print_r($this->ravelex_db);
            
$q $this->ravelex_db->get('users');
            return 
$q->result();
        }
    }

    
//smf_user_model.php
    
class smf_user_model extends Model {
        private 
$smf_db;
        
        function 
smf_user_model() {
            
parent::Model();
            
$this->smf_db $this->load->database('smf'TRUE);
        }
        
        function 
find_all() {
            
$q $this->smf_db->get('members');
            return 
$q->result();
        }
    } 
Controller tester

PHP Code:
class mutipledb extends Controller {
        
        function 
mutipledb() {
            
parent::Controller();
            
$this->load->database();
            
$this->load->model('user_model');
            
$this->load->model('smf_user_model');
        }
        
        function 
index() {
            
print_r($this->user_model->find_all());
            
print_r($this->smf_user_model->find_all());
        }
    } 
There are some error, The first database uses the second database name. But it still use it's prefix.

PHP Code:
The error is
    A Database Error Occurred
    Error Number
1146
    Table 
'smf.rvx_users' doesn't exist
    SELECT * FROM (`rvx_users`) 
gun41zuntuk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-23-2010, 08:55 PM Re: Error using multiple database using CodeIgniter
Novice Talker

Posts: 10
Name: adi sembiring
Trades: 0
help me please ....
gun41zuntuk is offline
Reply With Quote
View Public Profile
 
Old 01-27-2010, 11:50 PM Re: Error using multiple database using CodeIgniter
Junior Talker

Posts: 1
Trades: 0
Hi gun41zuntuk,

According to this post http://codeigniter.com/forums/viewthread/136871/ on CodeIgniter forum, you should set ['pconnect'] TO FALSE

Hope this help

Tommy
tommylinh is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Error using multiple database using CodeIgniter
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12161 seconds with 12 queries