Re: INSERT Array Values into mySQL Table - SOLVED!
| From: | Rahul Sitaram Johari | Date: | Wed, 02 May 2007 17:16:26 +0000 |
| Subject: | Re: INSERT Array Values into mySQL Table - SOLVED! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254246@lists.php.net to get a copy of this message | ||
WORKS Like A Charm!! :)
Thanks.
On 5/2/07 12:14 PM, "Brad Fuller" <bfuller@cpacampaigns.com> wrote:
> 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.
>>
>> JM
>
> Good point, Jim. I just realized that. I actually use this method in one
> of my scripts; in my case all of the fields are varchar and the code below
> works perfectly. This is updated to quote all values.
>
> $sql = "INSERT INTO coreg_lead (".implode(",",
> array_keys($dbFields)).")
> VALUES ('".implode("','",
> array_values($dbFields))."')";
>
> -Brad