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 8709965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:30:09+00:00 2026-06-13T04:30:09+00:00

I’m using 2 different databases on my CI app. I created 2 users on

  • 0

I’m using 2 different databases on my CI app.

I created 2 users on mysql, and granted user1 to db1 all privileges, then user2 to db2 all privileges with SQLpro client.

The database.php:

$active_group = 'default';
$active_record = TRUE;   

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '***1';
$db['default']['password'] = '***1';
$db['default']['database'] = 'ci_users';
$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_unicode_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

$db['keys']['hostname'] = 'localhost';
$db['keys']['username'] = '***2';
$db['keys']['password'] = '***2';
$db['keys']['database'] = 'ci_keys';
$db['keys']['dbdriver'] = 'mysql';
$db['keys']['dbprefix'] = '';
$db['keys']['pconnect'] = TRUE;
$db['keys']['db_debug'] = TRUE;
$db['keys']['cache_on'] = FALSE;
$db['keys']['cachedir'] = '';
$db['keys']['char_set'] = 'utf8';
$db['keys']['dbcollat'] = 'utf8_unicode_ci';
$db['keys']['swap_pre'] = '';
$db['keys']['autoinit'] = TRUE;
$db['keys']['stricton'] = FALSE;

The models:

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_Users extends CI_Model {
    function Model_Users()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->database('default',true);
    }
etc...


<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_Keys extends CI_Model {
    function Model_Keys()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->database('keys',true);
    }
etc...

So when using both models in same controller/method the model_users works great but model_keys returns an error, because it seems to load anyway the model_users db1 instead ofl oading db2:

Cannot modify header information – headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/app/application/models/model_keys.php:2)
Filename: core/Common.php
Line Number: 442

A Database Error Occurred
Error Number: 1146
Table ‘ci_users.ci_keys’ doesn’t exist //this should be ci_keys.ci_keys

Does anyone has idea?

I edited code in model_keys:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_Keys extends CI_Model {

    function Model_Keys()
    {
        // Call the Model constructor
        parent::__construct();
        $this->db_keys = $this->load->database('keys',true);
    } 

Now db works but I receive session error on model:

Message: Cannot modify header information – headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/site/application/models/model_keys.php:2)

In controller i’m doing this:

$this->load->model('model_users');
$this->model_users->insert(bla bla);

$this->load->model('model_keys');
$this->model_keys->insert(bla bla);

$this->session->set_userdata(array(bl bla);

redirect(some url);
  • 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-13T04:30:10+00:00Added an answer on June 13, 2026 at 4:30 am

    Below line is problem

    $this->load->database('keys',true);
    

    If you pass second argument TRUE, then it will return database object and it will not work with ActiveRecord.

    Here is example

    $DB1 = $this->load->database('group_one', TRUE);
    
    //Then you can't below function
    $this->db->query();
    
    You will instead use:
    
    $DB1->query();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.