NYCPHP Meetup

NYPHP.org

[nycphp-talk] confused by classes

chris cwf at axlotl.net
Mon May 3 21:39:36 EDT 2004


On Sunday 02 May 2004 11:10 pm, Daniel Convissor wrote:
> First, your coding style needs improvement.  See
You think I have a coding *style*? ..Gee, thanks!

> Assign the return by reference in order to conserve memory, etc:
>       $dbh =& DB::connect($dsn);
Good to know 

> quote() is deprecated.  Use quoteSmart().
And thanks for this and the others.
>
> It's not clear what you're looking for here.
What I'm looking for is an answer to a general design question. I see three 
vaguely defined ways of doing this.
 Should I make the functions generic, and customize the sql in the script 
(that is, write a specific query and pass that and an array of parameters for 
each specific need, reusing a very generic DB connect/query function)?

$res = ("SELECT $sql, $data")

 Or is it better to code a catch all query in the function, and return a bunch 
of methods like this (my most recent brainstorm):

$res = ("SELECT w, x, y, y, z
              FROM [...])

Returns an array, or:

$this->one = $res[0];
$this->two = $res[1];
$this->three = $res[2];
...etc...

Or, lastly, is it best to make a bunch of rather specific functions with 
queries hard coded in them, but which are only returning tightly restricted 
datasets:
function a(){
$res = ("SELECT w FROM x");
return $res;}

function b(){
$res = ("SELECT y FROM z");
return $res;}

I guess I'm asking if I should be working with some general principle 
governing in which direction I should be pushing complexity. Towards the 
functions, or towards the scripts? Or should I just go away and run my head 
into a wall until I've learned enough to come back and ask more coherent 
questions (a reasonable answer, I would have to admit)?

Chris


> --Dan



More information about the talk mailing list