RE: [PHP] INSERT Array Values into mySQL Table
| From: | Richard Lynch | Date: | Wed, 02 May 2007 19:23:33 +0000 |
| Subject: | RE: [PHP] INSERT Array Values into mySQL Table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254253@lists.php.net to get a copy of this message | ||
On Wed, May 2, 2007 11:03 am, Jim Moseby wrote:
>>
>> $sql = "INSERT INTO table (f1, f2, f3, ". implode(",",
>> array_keys($pr1)) .")
>> VALUES ('abc', '123', '456', ".
>> implode(",",
>> array_values($pr1))
>> .")";
>>
>> HTH,
>>
>> Brad
>
>
> Might not work if the array values need to be enclosed in quotes. I
> would
> build the query string in a foreach loop and execute the query
> afterwards.
It's pretty trivial to convert to:
VALUE ('abc', '123', '456', '" .
implode("','", $array_values($pr1)) .
"')";
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?