Re: Multiple insertion querry
From: Nikolai Chuvakhin (nc_at_iname.com)
Date: 11/19/03
- Next message: Eric Kincl: "Re: need to send email to 1000 addresses (currently in MS Excel)- what's the best way to do that, create a mail forma and paste ALL 1000 addresses in the TO field?"
- Previous message: Google Mike: "MS SQL Server Connections"
- In reply to: Eric Kincl: "Multiple insertion querry"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 Nov 2003 14:30:44 -0800
Eric Kincl <Eric@Kincl.net_NO_SPAM_> wrote
in message news:<3fbbcc1f@news.gvsu.edu>...
>
> I have an array of data in PHP. I would like to insert each
> member of the array into it's own row in SQL. The array is
> of variable length, so it would have to be dynamic code.
> How would I go about this?
By compiling one hell of a long query and executing it at once.
This is much faster than any solution with multiple INSERTs.
$array = array ('Many', 'many', 'many', 'members');
$query = "INSERT INTO yourtable (yourcolumn) VALUES (('" .
implode ("'), ('", $array) .
"'))";
$result = mysql_query ($query);
If I put in the right punctuation, the variable $query must
contain:
INSERT INTO yourtable (yourcolumn)
VALUES (('Many'), ('many'), ('many'), ('members'))
Cheers,
NC
- Next message: Eric Kincl: "Re: need to send email to 1000 addresses (currently in MS Excel)- what's the best way to do that, create a mail forma and paste ALL 1000 addresses in the TO field?"
- Previous message: Google Mike: "MS SQL Server Connections"
- In reply to: Eric Kincl: "Multiple insertion querry"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|