Welcome Guest, Not a member yet? Register   Sign In
load->database() limitation or bug?
#1

[eluser]Unknown[/eluser]
I'm working on a simple Vbulletin integration with a portal, but I found a strange issue:

I have two functions in Member model, that retrieves user info. The first one retrieve info from VBulletin database and the second one retrieves Extra info from antoher db.

But the second function tries to retrieve info from the database of the first function, even with wrong prefix.

Here's the code:

Member Controller:
Code:
class Users extends Controller {
        public function ___construct()
        {
           .....
        }

        function index()....

    function username($username)
    {
        .... Assigning HTML title, CSS, JS for this controller to pass later to view
//USER DATA
        $this->load->model('membro');
        $info['vbinfo'] = $this->membro->getUserInfo($username);
        if ($info['vbinfo']->userid > 0) {
            //EXTRA DATA
            $info['info'] = $this->membro->getUserBasicInfo($info['vbinfo']->userid);
        }
        
        //MODULOS
        $data['modulos'] = $this->load->view('membros/membroModule', $info, TRUE);

The Member Model:
Code:
class Membro extends Model {
    
    private $results;
    
    public function __construct()
    {
        parent::Model();
        $this->results = new stdClass();
        $this->results->username = 'guest';
        $this->results->userid = -1;
        $this->results->usergroup = 0;
        
    }
    
    public function getUserInfo ($username)
    {
        $this->load->database('vb');
        $this->db->from('user')->where('username', $username)->limit(1);
        $query = $this->db->get();
        if ($query->num_rows > 0) $this->results = $query->row();
        $this->db->close();
        
        return $this->results;
    }
    
    public function getUserBasicInfo ($userid)
    {
        $results = new stdClass();
        $results->paisOrigem = ('00');
        $results->estadoOrigem = ('00');

        $this->load->database('default');
        $this->db->from('user_info')->where('userid', $userid)->limit(1);
        $query = $this->db->get();
        if ($query->num_rows > 0) $results = $query->row();
        
        return $results;
    }
    
}

The DB Config (database.php):
Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "portal";
$db['default']['dbdriver'] = "mysqli";
$db['default']['dbprefix'] = "portal_";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_unicode_ci";
//VBulletin Database
$db['vb']['hostname'] = "localhost";
$db['vb']['username'] = "";
$db['vb']['password'] = "";
$db['vb']['database'] = "vbulletin";
$db['vb']['dbdriver'] = "mysqli";
$db['vb']['dbprefix'] = "forum_";
$db['vb']['pconnect'] = FALSE;
$db['vb']['db_debug'] = TRUE;
$db['vb']['cache_on'] = FALSE;
$db['vb']['cachedir'] = "";
$db['vb']['char_set'] = "utf8";
$db['vb']['dbcollat'] = "utf8_unicode_ci";

When i do this:
Code:
$this->load->model('membro');
        $info['vbinfo'] = $this->membro->getUserInfo($username);
And pass to view, i got the correct info. Only from VBulletin.

OR when i do this:
Code:
$this->load->model('membro');
        //$info['vbinfo'] = $this->membro->getUserInfo($username);
$testuser = 50;        
if ($testuser > 0) {
            //EXTRA DATA
            $info['info'] = $this->membro->getUserBasicInfo($testuser);
        }
I got the correct extra info for the desired user.

But when i tried the first controller code, loading vbulletin info first, and if exists user, load extra info, i got no luck. I got this error:
Code:
A Database Error Occurred

Error Number: 0

SELECT * FROM (`forum_user_info`) WHERE `userid` = '50' LIMIT 1

It clear that CodeIgniter is searching in the wrong database config. The correct should be ('portal_user_info'), that leads to default DB config, and not the VB config.

Any tips, or this is really a bug?

For me it looks a limitation bug, because i used $this->load->database() twice in the same model, for different DBs.


Messages In This Thread
load->database() limitation or bug? - by El Forum - 06-23-2008, 10:39 AM
load->database() limitation or bug? - by El Forum - 06-23-2008, 12:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB