2 databases and libraries - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: 2 databases and libraries (/showthread.php?tid=26460) |
2 databases and libraries - El Forum - 01-14-2010 [eluser]Maglok[/eluser] I have an app where I have a database for the app data and a database from a phpbb forum that provides login data. In my database.php I have the following: Code: /* APP */ I also extended the default Controller as follows: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I can now use $this->db_forum->something to approach the forum db and $this->db_app->something to approach the application db. Here is where it goes wrong. I activated the profiler to see how my queries and were doing and got this: Code: A PHP Error was encountered Looked it up and the library has a reference to $this->CI->db->queries. But 'db' is not in use when using multiple databases. How do I circumvent this issue? Can one be a default for example? 2 databases and libraries - El Forum - 01-14-2010 [eluser]WanWizard[/eluser] looks like a typo, it should be '$db->queries'. 2 databases and libraries - El Forum - 01-15-2010 [eluser]Maglok[/eluser] I don't think a core library has a typo really. That would make it a bug in CI. Libraries/Profiler.php is a core library. 2 databases and libraries - El Forum - 01-15-2010 [eluser]rogierb[/eluser] The profiler class assumes you have one db and use the standard connection. So you can't use it unless you extend it twice, for each connection once. Or rewrite it to pass the connection as a parameter. 2 databases and libraries - El Forum - 01-15-2010 [eluser]Maglok[/eluser] This whole 2 databases support thing isn't really working out for CI is it? dbforge was also giving me hell, not supporting a 2nd one. Oddly the profiler seems to work just fine, showing two queries boxes, and both working, it just throws those notices. 2 databases and libraries - El Forum - 02-02-2010 [eluser]Unknown[/eluser] Hi there, I also have similar problems with multiple database profiler. My application have two database groups, one is 'master' and the other is 'slave'. 'master' is the active group. I also write a base model class to make it easier to get the Master or Slave database connection and other model classes will have to extend this class. Code: class MY_Model extends Model In User model, I have the following function: Code: class User_model extends MY_Model Function getUser runs perfectly but the profiler can not capture the query executed. If I use $this->getMasterDb instead of $this->getSlaveDb, the same problem will occur. When looking through the CodeIgniter Loader class, I realize that if I set the second parameter of the function $this->load->database to TRUE to force the function return the database object, the database object will not be assign to $CI->db. Therefore, the profiler will not be able to display queries executed on the database. Code: function database($params = '', $return = FALSE, $active_record = FALSE) I also try to extend the CI Loader class to make sure that each database connection is assigned to a CI Super object's property. The profiler is now working as expected. Two queries boxes are display for Master and Slave connections. Code: class MY_Loader extends CI_Loader However, this is just a test, not a solution. I would really appreciate if you can help me solve the problem. p/s: I think it may be better to display the Database Group Name instead of the Database Name in the profiler since Master and Slave databases often have the same name but I currently don't know how. 2 databases and libraries - El Forum - 04-26-2010 [eluser]coldfire82[/eluser] I have the same query of working with 2 databases in CI. Is the problem resolved ? Any good solutions ? 2 databases and libraries - El Forum - 06-29-2010 [eluser]sqwk[/eluser] Tommy Lee's 'solution' works fine for me, however, it is interisting that the Profiler always lists "DATABASE: db-name QUERIES: 1" in the legend tag, even though there is more than one query. 2 databases and libraries - El Forum - 06-30-2010 [eluser]WanWizard[/eluser] I had to modify the _compile_queries method of the profiler library to have multiple DB detection work properly. I replaced Code: // Let's determine which databases are currently connected to Code: // Let's determine which databases we are currently connected to And indeed, the profiler can't access the query statistics if you create the database object locally, the way the manual says it: Code: $DB1 = $this->load->database('group_one', TRUE); But it does if you do Code: $this->DB1 = $this->load->database('group_one', TRUE); You can only access the 'groupname' in the profiler if you modify the CI core file DB.php, since that is where parsing of the parameter takes place (can be anything, from empty to a string to an array)... |