versatilewt Posted May 8, 2006 Share Posted May 8, 2006 I'm developing a script that has a large number of queries. I was wondering what techniques people use to manage queries (i.e. include file for queries?) throughout their php code. I've just been writing them in on the pages I use and executing via ADODB, but it's making the code pretty ugly.Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ober Posted May 8, 2006 Share Posted May 8, 2006 I'm not sure exactly what you're getting at. The only time I move queries to an include is if the WHERE clause gets really big and eats up a lot of page real estate. And if the query and resulting display work is only used once, I usually keep it on the same page.However, if you're doing a ton of formatting or setup work to display the results of the query and you have several of those, that's when I start to split it out. I have several pages that are nothing but includes to different reports since I have one page that all my reports get printed from in one of my applications. Then I just include whatever report is called from the switch().Quick question though... why use ADO? Unless you're using something like Access or MSSQL with field names > 30 characters, there's no reason not to use the built in libraries. ADO is really messy and not nearly as nice to deal with. Quote Link to comment Share on other sites More sharing options...
versatilewt Posted May 8, 2006 Author Share Posted May 8, 2006 I have a quite a few queries that have multiple joins, and I try to keep the SQL formatted nicely, which takes up quite a few lines.Regarding the ADODB question, I chose it partially for the easy session management and partially because the database might be changing in the future, and didn't want to have to re-code all of the query strings.For include files, do you name them .inc, .inc.php, .php? I have basically modules for the system, and for "contacts" for instance, i have view/edit/update pages, which all share similar queries. I'd like to stick them all in one file, however, I don't want to be wasting memory setting all of the queries for each page, if they only use a few of them That's pretty much my problem. Quote Link to comment Share on other sites More sharing options...
haydndup Posted May 8, 2006 Share Posted May 8, 2006 I tend to use .inc.php. NEVER use .inc as if anyone stumbles across one of your include file (eg db.inc), the browser will display the contents in plain text, say goodbye to you databse username and password... At least if you use .inc.php (or.php for that matter), the browser will just show a blank page coz you haven't told the php script to echo anything. Quote Link to comment Share on other sites More sharing options...
todd3834 Posted May 8, 2006 Share Posted May 8, 2006 Yes, I would use an include file like [b]WhyWindows[/b] said and create an array that contains all of your queries in that file. Just be sure to have .php on the end like he said too... Quote Link to comment 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.