Jump to content
Larry Ullman's Book Forums

"Non-View" Page Requiring Database Connection


Recommended Posts

Hi Larry, first of all, thankyou for writing such a helpful book :-)

 

As per the book examples, if I have a webpage that connects to the database, I need to include/require the config.inc.php file and than 'require' the MYSQL constant (defined in the config file).

My undestanding is that the above action will include the methods present in the two files 'mysql.inc.php' and 'config.inc.php' as well as start the session.

 

However, what if I require a database connection in a page that has nothing to display; instead it will simply be used to retrieve/SELECT some data (and then send it via JSON format for use in a JQuery ajax function)?

Will including the two files mentioned above and the subsequent inclusion of the unnecessary functions (functions such as the "redirect_invalid_user()" present in the config.inc.php file, which are unnecessary in this case) as well as starting the session result in any perfomance degradation?

Is there a 'more professional' way to handle such a scenario?

 

Thanks in advance for your response.

Link to comment
Share on other sites

Thanks for the nice words. It is appreciated. As for your question, will including those files with the unnecessary function definitions and session starting degrade the performance? By definition, yes. The question is whether or not it's perceptible, and the answer is probably "no". It will depend upon how demanding the site itself is.

 

A solution would be to separate out some of the configuration stuff into a new file. So the config file would only define what every page needs and you wouldn't have this problem. But then all the pages that do need that stuff would have to perform another include, which would degrade their performance.

 

My inclination would be to do this as the book does it, but it's a matter of opinion and personal preference.

Link to comment
Share on other sites

 Share

×
×
  • Create New...