Welcome Guest, Not a member yet? Register   Sign In
Profiler and Multiple DB's
#7

[eluser]dbrown75[/eluser]
I'm just staring out on building the code, so not accessing the default database yet.

I have a model that has multiple functions like :

public function get_data()
{

$second_database = $this->load->database('second_database', true);
$second_database->query('SET NAMES latin1');
$second_database->select("wp_posts.post_date 'date', wp_posts.post_title 'title', wp_posts.post_excerpt 'content', wp_posts.post_name 'slug', wp_users.display_name 'author'");
$second_database->join('wp_users', 'wp_users.ID = wp_posts.post_author', 'left');
$second_database->join('wp_post2cat', 'wp_post2cat.post_id = wp_posts.id', 'left');
$second_database->where('wp_post2cat.category_id = 71');
$second_database->where('wp_posts.gt_status = 1');
$second_database->where("wp_posts.post_status = 'publish'");
$second_database->where("wp_posts.post_date <= NOW()");
$second_database->orderby('wp_posts.post_date', 'DESC');
$query = $second_database->get('wp_posts', 1);

if ($results = $query->result())
{
$post = $results[0];

$post->permalink = 'http://www.mywebsite.com/'
. date('Y', strtotime($post->date)) . '/'
. date('n', strtotime($post->date)) . '/'
. date('j', strtotime($post->date)) . '/'
. $post->slug . '/';

$post->content = strip_tags(trim($post->content), '<img>');
$post->content = nl2br($post->content);
$post->content = strip_tags(trim($post->content), '<img>');

return $post;
}
else
{
return false;
}
}

using the above code, only the default shows up with zero queries which is right as I'm not hitting the default yet, but shows nothing for the second_database.

If I add $CI =& get_instance(); and switch $second_database over to $CI->$second_database, I can get the last functions queries I call to show up but not all of them. That is I have 3 functions each that call the second_database, all using the above syntax, so I'd expect to see the query count at 6, not 2. The queries between the function a differ, in that one looks for category_id = 71, the other looks for category_id = 69 and the third looks for the most recent and doesn't filter by category_id.


Messages In This Thread
Profiler and Multiple DB's - by El Forum - 04-02-2009, 02:15 PM
Profiler and Multiple DB's - by El Forum - 04-02-2009, 08:50 PM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 06:11 AM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 06:47 AM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 06:59 AM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 07:09 AM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 07:32 AM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 08:11 AM
Profiler and Multiple DB's - by El Forum - 04-03-2009, 12:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB