Welcome Guest, Not a member yet? Register   Sign In
What do people think about auto-connecting the database?
#1

[eluser]Doug Lerner[/eluser]
In the database class docs it says:

Quote:The "auto connect" feature will load and instantiate the database class with every page load. To enable "auto connecting", add the word database to the library array, as indicated in the following file:

application/config/autoload.php

If your application is a database-driven one, that certainly seems convenient. Is it very inefficient to do that? Should I try to only have the database connected in classes that need it? Or is the overhead of connecting on each page relatively low?

Thanks,

doug
#2

[eluser]Daniel Walton[/eluser]
It's pretty negligible. Saying that though, lets pretend that your homepage has come under some ddos type attack from a bot, is it considered negligible then? I would probably say no. What type of application are you building? how many unique views do you have, and what percentage are database driven? Another thing to consider is building/using other autoload libraries that may rely on, but not explicitly load, the database class.
#3

[eluser]Doug Lerner[/eluser]
[quote author="Daniel Walton" date="1215784055"]It's pretty negligible. Saying that though, lets pretend that your homepage has come under some ddos type attack from a bot, is it considered negligible then? I would probably say no. What type of application are you building? how many unique views do you have, and what percentage are database driven? Another thing to consider is building/using other autoload libraries that may rely on, but not explicitly load, the database class.[/quote]

Good points. By the by, in some other code, I saw the database loaded as follows:

Code:
$CI =& get_instance();
    if(empty($CI->db)) $CI->load->database();

Is that considered good practice? Does it save time? Or is CI clever enough not to "reload" the database by itself if it is already loaded?

doug




Theme © iAndrew 2016 - Forum software by © MyBB