Question by EvilDesire
This is a general question.
I have a website with a page showing many elements of my database.
And in this page I have a script where I’m loading these elements.
The the thing I want to know is it alright to load the database at the display of the page, knowing that everytime user will click and reload the page, my script will reload everything again from my database?
Is it a proper way to do it? Like creating an init.php at the first loading of the website, and storing my elements into a $_SESSION?
I don’t know if I managed to explain my problem, so please ask me more informations if needed.
Answer by Starx
The concept is pretty simple.
If you are sending a new request, it is wise to always start a new connection when needed and close it when its done.
But do not store the connection or any results in SESSION, as this can cause security issues. Creating a common script to start adn close a connection is the way to go.
Having said that look at persistent connections is it probably the thing you want.