[thelist] PHP tip

shawn allen shawn at alterior.net
Tue Feb 4 15:33:01 CST 2003


quoth rudy:
> > In the case of empty strings, I can also proof on the client side by
> > inserting NULL into a field before it is submitted.
>
> that might work, and it might not
>
> when you prepare the sql insert statement on the server side, you'll
> have to catch those values anyway, so that you don't automatically
> enclose them in quotes, and in that case, you might as well detect the
> empty field instead
*snip*
> shawn's array_walk() sounds like it might allow you to do this
> tweaking (i'm not sure because i don't do php)

You could very easily modify db_quote() (at this point, you'd probably
want to rename the function though, since it's not simply quoting) to
submit NULL's instead of empty strings. As rudy also mentioned, though,
you could just as easily *not* provide those columns in the INSERT
statement to begin with. You could just loop over the array and drop the
keys with empty values:

foreach ($row as $column => $value)
    if (empty($value)) unset($row[$column]);

Voila!

--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list