Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:56:28+00:00 2026-06-10T12:56:28+00:00

I have a trouble with dbutil and db. Below is my code (a constructor

  • 0

I have a trouble with dbutil and db.
Below is my code (a constructor of my model):

public function __construct(){
    // I save my database configuration in CI session
    $this->load->library('session');
    $config = $this->session->userdata("db_config");
    if($config){ // $config is now equal contains of my database configuration
        $this->db = $this->load->database($config, TRUE);
    }else{
        $this->db = $this->load->database();
    }       
    $this->load->dbutil();
    echo '<pre>'.print_r($this->db, TRUE).'</pre>';
    echo '<pre>'.print_r($this->dbutil, TRUE).'</pre>';
}

I found that $this->db and $this->dbutil point to different databases.

$this->db point to database config from session:

....
[username] => root
[password] => toor
[hostname] => localhost
[database] => coba
....

While $this->dbutil point to database config from my configuration file (application/config/database.php):

....
[username] => root
[password] => toor
[hostname] => localhost
[database] => module_devel
....

This is not expected, since I expect both of $this->db and $this->dbutil point to the same database

I’ve also check PHP: CodeIgniter; Managing two db connections; variable database parameters. But, for me the solution doesn’t work at all.

So, anyone can discover what’s wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:56:29+00:00Added an answer on June 10, 2026 at 12:56 pm

    It seems that it is a bug of CodeIgniter. But, dbutil is not the only we can use.
    There are many alternatives to emulate what dbutil can do.

    In my case, I want to generate a “create table” script. I end up using

     $query = $this->db->query("SHOW CREATE TABLE `$table_name`");
    

    And to generate SQL insert script, I do manual select, loop through the records and produce the script.

    Hope this can help anyone else with similar problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble finding way to correctly refactor this code so that there would
i have trouble with optimization of the code below which is changing css property
I have trouble understanding this chunk of code: let sieve (p:xs) = p :
I have trouble understanding the underlying errors with the code below: class myClass {
I have trouble figuring out why a simple division like this one always returns
We have trouble implementing a nice session mechanism in JSP. One of our requirement
I have trouble doing this... You may want to get the same result as
I have trouble saving my date field into database using CakePHP. Table column name
I have trouble compiling a class, which has function pointers as member variables. The
I have trouble with deleting all of layer's sublayers. I currently do this manually,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.