Welcome Guest, Not a member yet? Register   Sign In
Can't select database using extended controller. regular controller works.
#11

[eluser]bill19[/eluser]
Hi everyone,

It appears that in fact it is the ion_auth library which is causing the problem. It looks like there is a bug preventing switching of databases if ion_auth is loaded. I combined the ion_auth tables into my other DB, and now everything is working properly.

Hope this helps someone,

Bill
#12

[eluser]kptengco[/eluser]
Code:
$DB1 = $this->load->database('default', TRUE);
        $DB2 = $this->load->database('wo', TRUE);

public function listings()
    {
        
        var_dump($this->the_user);
        echo 'in home listing';
        echo "<pre>";
print_r($this->db->list_tables());

echo "<pre>";
print_r($this->DB2);
Change
Code:
print_r($this->db->list_tables());
to
Code:
echo print_r($DB1->list_tables()); or  echo print_r($DB2->list_tables());

You don't have to use
Code:
$this->db->
since you load a database and pass it to a variable by that you'll have to replace
Code:
$this->db->
to your variable
Code:
$DB1->get('table');
#13

[eluser]Ben Edmunds[/eluser]
So which DB do you want Ion Auth to use?
#14

[eluser]bill19[/eluser]
Ben,

Thanks for taking a look at this.

I am using the 'default' DB to connect to a separate ion_auth DB, and this works. I want to switch to a second DB entitled 'wo' with config/database file listed above listed above.

Kptengco,

Thank you for the code examples. That helped clarity the syntax for me.

Regards,

Bill
#15

[eluser]Ben Edmunds[/eluser]
So do you have it working now?

If not, are you saying you want Ion Auth to use "wo" or default"?
#16

[eluser]bill19[/eluser]
Hi Ben,

My original setup was a database named 'ion_auth' which I created solely for use by your auth system. It contains only the 3 ion_auth tables. my second DB , 'wo' is a wordpress DB , which I wanted to access.

My Plan was to have the user login using the ion_auth DB, then switch to 'wo' ( or at least be able to access it ) I was never able to get this working , so my workaround was to dump the 3 ion_auth tables into 'wo',and set 'wo' as 'default', so I never had to switch DBs.

Using this workaround I was able to get my code working, but I'd still like to know how to switch DBs , if you wouldn't mind.

Bill
#17

[eluser]Ben Edmunds[/eluser]
You can switch DBs like this:

Code:
$DB1 = $this->load->database('default', TRUE);
$DB2 = $this->load->database('wo', TRUE);

and then the key is to overwrite the $this->db object with the db you'd like to use in you're libraries with

Code:
$this->db = $DB2;
#18

[eluser]bill19[/eluser]
Thanks Ben, it does work providing I set:

Code:
$DB1 = $this->load->database('default', TRUE);
$DB2 = $this->load->database('wo', TRUE);

inside a function. I originally had them within the constructor.

Best regards,

Bill
#19

[eluser]CroNiX[/eluser]
You should be able to define them like that in the constructor, and then use $this->DB1 and $this->DB2 to access them from your methods.

Although, I don't think you need to load this one assuming you are already loading your default database:
Code:
$DB1 = $this->load->database('default', TRUE);
If you are just use $this->db like normal to use your default. You only need to define the 2nd connection.

Code:
class Something extends Something_else {

  public $db_wo;

  function __construct()
  {
    parent::__construct();

    //Create the 2nd db connection
    $this->db_wo = $this->load->database('wo', TRUE);
  }

  function sample()
  {
    //Access default db
    $data = $this->db->select(...)->get(...)->result();

    //Access wo db
    $wo_data = $this->db_wo->select(...)->get(...)->result();
  }
}
Does that work for you?
#20

[eluser]bill19[/eluser]
Hi CroNiX,

Yes, that works. Thanks for the explanation.

Bill




Theme © iAndrew 2016 - Forum software by © MyBB