NYCPHP Meetup

NYPHP.org

[nycphp-talk] SQL 'WHERE' conditions in an array

Kenneth Downs ken at secdat.com
Wed Aug 3 12:18:07 EDT 2005


You may want to look up "binary decision trees".  This is not precisely
what you are looking for but it is closely related and may give you some
background.

The basic idea behind any generated SQL statement is the fact that SQL
statements that follow certain rules can themselves can be stored entirely
in scalar data.

Imagine this simple array:

$Query = Array
(
   "tables"=> Array
   (
       [0] = Array
       (
          "table_name"=>"customers"
       )
   )
)

or the more detailed:

$Query = Array
(
   "tables"=> Array
   (
       [0] = Array
       (
          "table_name"=>"customers"
          "columns"=> Array
          (
             "column1",
             "column2",
             "column3"
          )
       )
   )
)

Your code just loops through building a SELECT clause from the tables.  If
it cannot find the "columns" sub-array it puts in "*", else it lists the
columns in that array.

Everything else is just an embellishment of this, and of course remember
TIMTOWTDI.


> Hello,
> A while ago I've seen some code (function) to build SQL queries. It took a
> multidimentional associative array to build complex WHERE conditions.
> That's
> the feature that I really liked. I'm trying to find it again to no avail.
> Can someone point me to that code please?
>
> Thanks,
> Olaf
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org


-- 
Kenneth Downs
Secure Data Software
631-379-0010
ken at secdat.com
PO Box 708
East Setauket, NY 11733




More information about the talk mailing list