Welcome Guest, Not a member yet? Register   Sign In
[Solved] Profiler only shows queries to one database
#1

[eluser]sqwk[/eluser]
I am trying to find an error using the profiler, however, it only seems to list queries to the default database. I know there is definitely a query to a second database, which is not being shown.

How do I tell the profiler to show all queries?
#2

[eluser]danmontgomery[/eluser]
The profiler should catch queries for all database objects that are assigned to the CI superobject... So, assuming you are doing something like:

Code:
$db1 = $this->load->database('db1', TRUE);
$db2 = $this->load->database('db2', TRUE);

In the controller, you should be able to just do:

Code:
$this->db1 = $this->load->database('db1', TRUE);
$this->db2 = $this->load->database('db2', TRUE);

There's been some discussion about this (http://ellislab.com/forums/viewthread/141499/) and I haven't tried it myself, but it should work.
#3

[eluser]sqwk[/eluser]
In the controller? I load the db in the model like this:

Code:
$geo = $this->load->database('geodb', TRUE);

$geo->query('bla bla bla');

Is this the wrong way to do this?
#4

[eluser]danmontgomery[/eluser]
No, it's not wrong, the queries just won't show up in the profiler unless the DB object is a member of the CI superobject
#5

[eluser]sqwk[/eluser]
… and in order to become a member of the superobject they need to be in the controller?

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

I added the this-> in the model but it doesn't make the query show up in the profiler.
#6

[eluser]sqwk[/eluser]
Only just read the whole thread that you linked earlier…

Loading in the model works just fine but you need to extend the CI Loader class: http://ellislab.com/forums/viewthread/141499/#706357

And the $this-> is not actually needed…
#7

[eluser]slowgary[/eluser]
In my application I don't need 2 connections, but I do need to replace the connection with a high privileged database user after login. If this helps anyone, here's how I've done it:
Code:
// config/database.php
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "192.168.0.50";
$db['default']['username'] = "visitor";
$db['default']['password'] = "password";
$db['default']['database'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

$db['privileged']['hostname'] = "192.168.0.50";
$db['privileged']['username'] = "admin";
$db['privileged']['password'] = "admin_password";
$db['privileged']['database'] = "";
$db['privileged']['dbdriver'] = "mysql";
$db['privileged']['dbprefix'] = "";
$db['privileged']['pconnect'] = TRUE;
$db['privileged']['db_debug'] = TRUE;
$db['privileged']['cache_on'] = FALSE;
$db['privileged']['cachedir'] = "";
$db['privileged']['char_set'] = "utf8";
$db['privileged']['dbcollat'] = "utf8_general_ci";


// base controller
// grab past query data from existing database object
$queries    = $this->db->queries;
$query_times    = $this->db->query_times;

// overwrite database object with new, higher privileged object
$this->db = $this->load->database('privileged', TRUE);

// add queries back to new object
$this->db->queries        = $queries;
$this->db->query_times        = $query_times;

// go about our merry way



This worked for me. I hope this helps someone else on the hunt.




Theme © iAndrew 2016 - Forum software by © MyBB