|
Posted by strawberry on 04/13/07 10:07
On Apr 13, 10:27 am, Schraalhans Keukenmeester
<bitbuc...@invalid.spam> wrote:
> strawberry wrote:
> > On Apr 13, 9:08 am, Schraalhans Keukenmeester <bitbuc...@invalid.spam>
> > wrote:
> >> strawberry wrote:
> >>> On Apr 13, 1:51 am, "strawberry" <zac.ca...@gmail.com> wrote:
> >>>> I'm trying to extend a class (written by others) and was wondering if
> >>>> there's a standard a way of passing a $_GET request to a class. Here's
> >>>> what I have (see below). If I hardcode $where, something like
> >>>> $where = " WHERE `firstname` = 'John' "
> >>>> and then pass it as an argument into the scope of a 'select' function
> >>>> then it works fine, but otherwise the query just appears to hang.
> >>>> I'm deliberately not including the class or class extender at this
> >>>> stage, but I'll add them to this thread later if required.
> >>>> foreach ($_GET as $condition_key => $condition_value) {
> >>>> $condition[] =" $condition_key = '$condition_value' ";
> >>>> }
> >>>> if(is_null($condition)){
> >>>> $where = " WHERE 1 ";
> >>>> }else{
> >>>> $conditionString = implode('AND', $condition);
> >>>> $where = " WHERE $conditionString ";
> >>>> }
> >> You're reposing the question? Or ?
>
> > No. I just wanted to get the thread into comp.lang.php too
>
> The hardcoded version has single quotes around key and value, your $_GET
> parsed version hasn't in this example. Could that be the cause? Does the
> query run with results if NO conditions are set?
>
> Sh.
? It's true that the column name was missing the backticks - but that
would only be an issue when using a reserved word. Anyway, I've added
them:
.../test.php?Planet=Mars
echo $where;// WHERE `Planet` = 'Mars'
However, if I add the following line to the class...
global $where;
And then deliberately enter a non-existent column name I get this...
Unknown column 'firstname' in 'where clause'
.... so the implication is that the query is getting through.
I really need to be sure that I'm looking at the exact same query as
that being executed by mysql. Is there an obvious way to do that, or
would one need to examine the class in more detail?
[Back to original message]
|