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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:30:36+00:00 2026-06-08T14:30:36+00:00

I’m not autoloading db because most pages of my application don’t need db processing

  • 0

I’m not autoloading db because most pages of my application don’t need db processing otherwise whole thing will slow down. What I want to do is not to establish a new connection to db when there is one already alive and use it instead not to bother server-db. So how do I implement $this->db->reconnect(); to my example below? I read user guide but no exact example there.

Note : If I necessary to use $this->db->close(); and $this->db->initialize(); then please help me implement them as well because I heard that calling $this->db->reconnect(); with autoloading disabled will throw an error.

I’m using CI 2.1

Thanks

class Test_model extends CI_Model
{
 public function __construct()
 {
  parent::__construct();

  $this->load->database();
 }

 public function function_a($id)
 {
  $this->db->protect_identifiers('year');

  $sql = "SELECT * FROM year WHERE id = ?";

  $data['dbquery'] = $this->db->query($sql, array($id));

  return $data['dbquery'];
 }

 public function function_b($id)
 {
  $this->db->protect_identifiers('month');

  $sql = "SELECT * FROM month WHERE id = ?";

  $data['dbquery'] = $this->db->query($sql, array($id));

  return $data['dbquery'];
 }


 public function function_c($id)...
 public function function_d($id)...
 public function function_e($id)...
} 
  • 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-08T14:30:40+00:00Added an answer on June 8, 2026 at 2:30 pm

    Basically if you keep pconnect=false in database.php then the connection will be closed at the end of each script’s execution automatically and by default it set to false.

    Well if you want then you can use

    $this->db->close();
    

    after every query execution to close the connection manually and use

    $this->db->initialize();
    

    before any query execution to initialize the connection again after closing it.

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

Sidebar

Related Questions

I disabled auto-loading db just because many pages of my site don't need db
I'm hesitating whether or not to use this mechanism. PHP Doc says autoloading is
Firstly, I'm not using rails. This is vanilla ruby application. I've read about packaging
I need to use autoloading for my custom classes in Zend Framework 2.0 .
Are traits in php5.4 subject to autoloading? I've not yet got an environment to
Not a web developer so i hope you will spare me if this question
Not sure how to frame this one, so here goes... I have a need
Not ever sure if it can be done, but is it possible to use
Not crazy about the way Xcode 4.2 has laid out the files on disk.
Not able to download artifacts from central maven repository. <mirrors> <!-- mirror | Specifies

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.