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

  • Home
  • SEARCH
  • 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 6173281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:32:42+00:00 2026-05-23T23:32:42+00:00

I am developing a Codeigniter (2.0.2) Application, which will utilise a Master database for

  • 0

I am developing a Codeigniter (2.0.2) Application, which will utilise a Master database for all write operations (INSERT/UPDATE/DELETE) and a read replica for all read operations (SELECT).

Now I know I can access two different database objects within the code to route the individual requests to the specific database server, but i’m thinking there has a better way, automated way. I’ll be using MySQL and Active Record, and also want to build in Memcache checking – although it won’t be used immediately, I’d like the option there for the future, built in at this stage.

I’m thinking if its possible to add a hook/library of some kind to intercept the $this->db->query so that the following happens:

1) SQL Query received

2) Check if SELECT query

2a) If SELECT, see if Memcache is active, if so encode SQL and check Memcache for response.

2b) If no memcache response, or Memcache is not active, execute query as normal through READ MySQL server.

3) Query was NOT select, so execute query as normal through the WRITE MySQL server.

4) Return response.

I’m sure that looking at this, it should be quite simple to do, but no matter how I look at it i’m just not seeing a potential answer – but there’s got to be one! Can anyone help/assist?

In addition, I also want the ability to be able to log all write SQL commands for troubleshooting, presumably the best way is to introduce 3a) Write SQL command to plain text file … into the above scheme. I don’t believe MySQL actually logs the non-SELECT queries in anyway … does it?

  • 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-05-23T23:32:42+00:00Added an answer on May 23, 2026 at 11:32 pm

    That type of behavior is a little bit beyond the normal scope of CI. Unfortunately, your best bet is to manually extend the database drivers, specifically override the function simple_query or _execute (simple_query is a wrapper around _execute which simply ensures initialization). That is really the only place where you can guarantee that you can catch all of the queries and branch the logic accordingly. (You may also want to override close as that is the cleanup script)

    (Personally, I would have a the SELECT DB load a secondary DB into itself and just call $write_db->simple_query conditionally, that seems like it would be the least trouble).

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

Sidebar

Related Questions

I'm developing a web based application built on codeigniter which will also have a
I'm developing web application using CodeIgniter. All this time, I put the custom js
When developing a new web based application which version of html should you aim
I'm developing a CodeIgniter based site that will be very multi language heavy. Plan
I am developing site using codeigniter.I have a form which contains add button and
I´m developing an application, where I´d like to have a button, which opens Androids
I'm about to start developing a new web application in CodeIgniter. In the past,
I am developing a website using CodeIgniter and PHP. Some of my friends suggest
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.

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.