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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:11:38+00:00 2026-05-27T03:11:38+00:00

I have done many CodeIgniter projects and in that i have only used $this->db->query

  • 0

I have done many CodeIgniter projects and in that i have only used $this->db->query and not any other methods.

People say that using this will complicate when we change the database.

So people use db->get, db->where and functions like that including join.

For example i am using mysql now with $this->db->query through out my project and if i am changing my database to any others … will it be a problem…

Besides we should be very clear of selecting the database before starting the project and this will be a good practice and people know about this… besides… this…

what will be the discrepancy if we only use $this->db->query in a CodeIgniter Project ?

Any type of answer would be helpful… advices, suggestions and answers. 🙂

  • 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-27T03:11:39+00:00Added an answer on May 27, 2026 at 3:11 am

    In some ways I see a benefit to using the Active Record classes, but in other ways it can be a deficit. Let me elaborate.

    As birderic said, the benefit of using the Active Record class is that CodeIgniter basically writes the t-SQL statements for you in the database engine that you have specified in your config.php file. Take for example the following code:

    $this->db->select('*')->from('users')->where('name', 'bob');
    $query = $this->db->get(0,10);
    

    Would generate this in MySQL: SELECT * FROM Users WHERE Name = 'bob' LIMIT 0, 10.

    And this in PostgreSQL: SELECT * FROM Users WHERE Name = 'bob' LIMIT 0 OFFSET 10

    The slight differences in the tSQL are taken care of by the Active Record class and it’s query builder. This is a huge benefit when you are either migrating your database, or testing your model code on a new datasource (maybe for unit testing with a SQLite database for instance).

    However, on the flip-side of the coin I think that typically databases tend to be more difficult to change and have a lot more “catches” when migrating. If you write all your code as Active Record code, then it is effectively forever tied to CodeIgniter. It is quite difficult to then shift that code and those queries to a new MVC framework, or even a new language down the road.

    Using the Active Record class gives you database freedom, but ties you down to CodeIgniter. Using normal SQL queries gives you framework freedom, but ties you down to your database.

    That said, I find a mixture of both works well. Sometimes my queries are quite complex and have sub-queries, all sorts of joins, weird SQL Server specific syntax … so then I have to use $this->db->query(). However, for all the simple stuff I use Active Record.

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

Sidebar

Related Questions

I have done this the other way many times as it makes sense (the
I have done a bit of research into this and it seems that the
I have done this many times and have never seen this. I have an
This is a very newbie question, and this is something I have done many
I have done this many times before, to re-use a value passed into the
I have done this many times in PHP using JS but being new to
This query runs when I comment out the code above '}else{'. Have done so
this is one of many EXC_BADACCES questions, but I have done research for a
I have done this many times in different apps but this is my first
I have done this successfully many times before, but this time it just won't

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.