• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Switching databases connection for use with $this->load->dbutil();

#1
[eluser]RECOHA[/eluser]
Hello Guys,

Sorry about the english, but I've a doubt about one thing.

Code:
public function fazBackup()
    {
        $banco['hostname'] = 'localhost';
        $banco['username'] = 'root';
        $banco['password'] = '';
        $banco['database'] = 'database';
        $banco['dbdriver'] = "mysql";
        $banco['dbprefix'] = "";
        $banco['pconnect'] = FALSE;
        $banco['db_debug'] = TRUE;
        $banco['cache_on'] = FALSE;
        $banco['cachedir'] = "";
        $banco['char_set'] = "utf8";
        $banco['dbcollat'] = "utf8_general_ci";
        
        $DB = $this->load->database($banco, TRUE);
        $DB->load->dbutil();

    }

This code returns:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_DB_mysql_driver::$load

Filename: intranet/ferramentas.php

Line Number: 42

Fatal error: Call to a member function dbutil() on a non-object in /home/hyadmin/hayaweb.com.br/application/controllers/intranet/ferramentas.php on line 42

I can't do this or I'm doing wrong?

Ty.

#2
[eluser]Christopher Blankenship[/eluser]
I am not exactly sure what you are attempting to do but maybe these links may help with your problem.
Codeigniter with Multiple Database Support
Codeigniter User Guide
Codeigniter Forum::connect to multiple databases

#3
[eluser]RECOHA[/eluser]
I'm trying to backup an external databases with dbutil() class.


I guess dbutil() class just can use with the databases setup in databases.php.

#4
[eluser]Christopher Blankenship[/eluser]
You can use dbutil() to backup databases and multiple databases at that you just need to setup the databases like shown in the links I provided above then call the one you are wanting to backup.

#5
[eluser]RECOHA[/eluser]
But, I want to backup a lot of MySQL databases. Look, I have an database in my server containing the informations of another databases and I want to connect one to one at a time to backup them with dbutil() class.

Is that possible?

#6
[eluser]danmontgomery[/eluser]
You can't load from a database object, you load from the CI object. The dbutil class uses whatever is assigned to $this->db.

Code:
public function fazBackup()
    {
        $banco['hostname'] = 'localhost';
        $banco['username'] = 'root';
        $banco['password'] = '';
        $banco['database'] = 'database';
        $banco['dbdriver'] = "mysql";
        $banco['dbprefix'] = "";
        $banco['pconnect'] = FALSE;
        $banco['db_debug'] = TRUE;
        $banco['cache_on'] = FALSE;
        $banco['cachedir'] = "";
        $banco['char_set'] = "utf8";
        $banco['dbcollat'] = "utf8_general_ci";
        
        $this->db = $this->load->database($banco, TRUE);
        $this->load->dbutil();

    }

If you're doing this across multiple databases, you still want to explicitly assign the object, because even though CI assigned the db to $this->db, if one is already loaded it won't load it again unless you tell it to. You probably want to also include a call to $this->db->close() between switching databases.

#7
[eluser]RECOHA[/eluser]
Thanks Lab Technician, but the code that you posted above don't work here.

Code:
A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 224

Sincerely.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.