Brent Baisley wrote:
> foreach($insert as $table => $fields) {
>       $fieldList = array_keys($fields);
>       $fieldNames = implode(',', $fieldList);
>       $fieldValues = '"'.implode('","', $fields).'"';
>       echo 'insert into '.$table.' ('.$fieldNames.') values
> ('.$fieldValues.')';
> }
>
> That puts double quotes around the values.

Which is not valid SQL, so won't work on most SQL engines.
[Though MySQL may be forgiving in this regard...]

$fieldValues = implode("', '", $fields);
would work on all standard SQL engines if ALL the fields were text (or
non-numeric).

Or, in MySQL, for integer/float as well, as MySQL lets you get away with
bogus (non-standard) apostrophes on numeric field values, so this will
"work" for MySQL even though it's morally wrong :-)

To make it really portable (standard SQL), you'd want to query your
database as to the type of each field and put apostrophes only around
non-numeric field values.

Or you could have some other way of keeping track of what's numeric and
what's not, of course.

> I always use single quotes
> around my text pieces since PHP doesn't parse what's inside them, thus
> it's supposed to be faster.

It's not measurably faster.

Even apostrophes have *some* internal processing (for embedded ' and \) so
there is no real difference in speed.

Benchmark it on your own machine to confirm.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to