Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 2 switching databases - Possible Bug.
#1

[eluser]sdjones[/eluser]
Hi Not sure if this is a bug but first some background info:

I have an application that needs to read in some xml and based on a nod ein that xml loads either a "live" database or a "test" database.

below is a snippet of code from my module:
Code:
<?php
Class Mercury_model extends CI_Model
{
var $cdb;
function setDB($db)
{
  $this->cdb = $this->load->database($db, TRUE);
}
...
?>

the important bit is this line:
Code:
$this->cdb = $this->load->database($db, TRUE);

when i use that and pass in the word test as follows from the controller:
Code:
$this->CI->mercury_model->setDB('test');

i get the following error:
Quote:You have not selected a database type to connect to.

however if i change the database load to the following:
Code:
$this->cdb = $this->load->database("$db", TRUE);

with the above in place i can successfully connect to either database on the fly. I dont understand when doing
Code:
$this->load->database($db, TRUE)
is different to
Code:
$this->load->database("$db", TRUE)

I would have thought both would produce the same output.

EDIT

just as FYI i already have the relevant config's set up in database.php

EDIT 2

after looking into this it appear to only happen with XML input, i am usign the following example:
Code:
<?xml version='1.0'?>
<mercury>
<msg>
<class>booking</class>
<version>1</version>
<function>get</function>
<login>Test</login>
<password>10</password>
<mode>test</mode>
</msg>
<booking>
<BookingID>123456</BookingID>
</booking>
</mercury>

any ideas?

works fine with the following JSON:
Code:
{
"msg" :
{
   "class":"booking",
   "version":"1",
   "function":"get",
   "login":"test",
   "password":"10",
   "mode":"test"
},
"booking":
{
   "BookingID":"123456"
}
}
#2

[eluser]Aken[/eluser]
There may be additional characters in the string, depending on how the XML is parsed, which is making it not match any existing DB configs.




Theme © iAndrew 2016 - Forum software by © MyBB