Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 3 only connect to database if theres queries to run?
#1

I'm using CI3 and I noticed that every time that I enter to any Controller a connection to the database is made even if is not needed.

I used the Profiler ( $this->output->enable_profiler(TRUE); ) to see the performance and when I remove the database library from the autoload.php the pages that don't use any queries loads a lot faster. I've read the Docs but don't see any related to connect to the database only when a query is needed, for the moment I'm only importing the ( $this->load->database(); ) in each model instead of importing it in the autoloader and loading the models only when needed.
Is there any easier option to this behaviour with the Database Library?

Thanks.
Reply
#2

@Yaiko,

I have just checked an old CI3 application and noticed that I have the following set:

File: ./app/config/autolload.php
Code:
// $autoload['libraries'] = array('database', 'image_lib','table' );
$autoload['libraries'] = array
(
    'database',
    // 'user_agent',
); //'table', 'image_lib',
#    'session',

Try removing the database auto loading and see what errors/warnings are created.

Also check the online documentation for: "Manually Connecting to a Database"
Reply
#3

Just to add to this, rather than it being a connection issues, check the pages that use the database have queries that are optimized.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#4

(04-22-2022, 10:19 PM)John_Betong Wrote: @Yaiko,

I have just checked an old CI3 application and noticed that I have the following set:

File: ./app/config/autolload.php
Code:
// $autoload['libraries'] = array('database', 'image_lib','table' );
$autoload['libraries'] = array
(
'database',
// 'user_agent',
); //'table', 'image_lib',
# 'session',

Try removing the database auto loading and see what errors/warnings are created.

Also check the online documentation for: "Manually Connecting to a Database"

Yes i tried removing database from the autoloader so the pages where no queries are ran load faster. but what I'm trying to do is that when having the database in the autoloader do not connect to the database until a first query is done. I didn't find any information in the documentation so I guess I will try create a custom function...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB