From: Richard L. <ce...@l-...> - 2010-05-18 04:24:32
|
I tend to try to keep things as simple as I can, but if I expect a project to get medium-sized... Lately, I've been using a Query object, which serves two roles: 1. A singleton for the database connection. 2. All queries live here, as static methods, and return arrays of objects or whatever the calling routine most needs. Because all the queries are in one place, I don't have to troll through files to try to find that slow query. Since all the DB-specific code is in one file, I know I can more easily swap it out if I have to. If there are specific data I expect to put into memcache or other data store, I'll abstract that further and handle it specially. When I first saw this, I hated it, but after giving it a try, I'm starting to like it more. Not sure it's the *best* answer, and for a massive project with thousands of different queries, it would need to be broken up or at least organized in the codebase. I do that anyway, physically grouping the methods for any given class/table/module, even for a handful of methods per model/class. On Thu, April 15, 2010 5:19 pm, junkmail wrote: > I am curious what people use for fetching data in PHP. I've been > calling > this my model. > Over the past few years I've slowly built up a framework that > encompassed basic mysql_connect() and mysql_query() wrapping for error > handling and simplicity. > For the next step I made a basic query generator for 1-table CRUD > operations using simple table definitions in associative arrays. > The next step is for complex CRUD with table joins. This is the hard > part that I'm not 100% sure how I should tackle it. I'm thinking it > will > start small, but ultimately I'll move to full-blown relationship > modeling with the ability to perform CRUD operations across any > relationship. > My goal is to write little-to-NO hardcoded SQL into my PHP. > > I'm curious to hear about any strategies on this problem, or any > insights that may have been encountered in similar endeavors. > > Thanks! > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > chiPHPug-discuss mailing list > chi...@li... > https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss > -- Some people ask for gifts here. I just want you to buy an Indie CD for yourself: http://cdbaby.com/search/from/lynch |