dprichard Posted June 19, 2007 Share Posted June 19, 2007 I have two queries that I will be running at the top of each page on my site once the user is logged in to pull in different information about them and to show the company's information. Would I be better off having these at the top of each page in the code or having them in includes and calling the includes? Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/ Share on other sites More sharing options...
GingerRobot Posted June 19, 2007 Share Posted June 19, 2007 If anything is done on many pages, then it is generally better to have them as includes. That way, they can be easily modified if any requirements change. The only thing is you should make sure they are necessary to the file when you include them - otherwise you will be slowing your site down for nothing. Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277901 Share on other sites More sharing options...
dprichard Posted June 19, 2007 Author Share Posted June 19, 2007 So, is there any performance loss having an include versus putting it directly in the page? Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277902 Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 I would recommend creating a functions.php file and putting your queries in a function and just call that function when you need it, so if you are going to use those functions just use the 'include' keyword to have them brought in to your php file. Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277903 Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 So, is there any performance loss having an include versus putting it directly in the page? Their may be but it is definitely not noticeable, plus this reduces rework . Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277905 Share on other sites More sharing options...
dprichard Posted June 19, 2007 Author Share Posted June 19, 2007 I was reading about functions. Is there an advantage to using a function versus an include? Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277906 Share on other sites More sharing options...
GingerRobot Posted June 19, 2007 Share Posted June 19, 2007 Firstly, no - there are no performance issues with using includes(to the best of my knowledge) since php processes an include as if the code were there in the file. Second, a function is a quite differant thing to an include - however, often people put functions which will be used throughout their site in one file, which they then include where it is needed. Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277919 Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 I was reading about functions. Is there an advantage to using a function versus an include? If code is included then that code will be executed (unless it's in a function) that's the difference. Quote Link to comment https://forums.phpfreaks.com/topic/56263-using-includes-for-queries/#findComment-277928 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.