472,958 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Multiple insertion querry

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? Would I stick
the SQL querry generation and actual querry into a while loop? This would
generate a lot of traffic between the SQL server and the PHP script.

The arrays are each over 1000 members long, however, this is an rare admin
script that will be run roughly 4 times a year, so I guess it isn't that
bad. If possible however, I would like to do it in one querry. Is that
possible? I thought I heard somewhere that it's impossible to run more
that one querry at once through PHP as a failsafe for users sticking bad
data into forms. (ie, you cant do: "querry1; querry2;", you have to do
"querry1;" querry it, then do "querry2;"

Thanks in advance,
-Eric Kincl
Jul 17 '05 #1
2 3160
Eric Kincl wrote:
[...] you cant do: "querry1; querry2;", you have to do
"querry1;" querry it, then do "querry2;"

with MySQL you can do a insert with multiple rows in a single query:

INSERT <table> [(col1, col2, ...)]
VALUES (val11, val12, ...),
(val21, val22, ...),
(valN1, valN2, ...)
PS. I'm more used to writing query :)

Jul 17 '05 #2
Eric Kincl <Er**@Kincl.net_NO_SPAM_> wrote
in message news:<3f******@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

INSERT INTO yourtable (yourcolumn)
VALUES (('Many'), ('many'), ('many'), ('members'))

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Raju V.K | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
by: Costa Lino | last post by:
Hi All, I have a DataSet with xml file and I want to make a querry like this DataView dv = new DataView(mytable); dv.RowFilter = " Impression < ( MaxImpressions) "; Impression et...
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
by: gabe_pu | last post by:
List Box Multiple Selections I have a list box on my page and Im trying to add new items on it. The insert operation must be under the selected item. When I make the insertion it is done ...
by: Clownfish | last post by:
OK, I'm having a brain freeze. I have a table like this: Office Name Phone ---------------------------------- SG Larry 555-1212 SG Moe 553-4444 SG Curly ...
by: toton | last post by:
Hi, I am looking for a circular buffer solution ( a fixed buffer) , where the elements can be pushed back & removed front. It looks stl deque can be a solution. my question is, 1) circular...
by: hellboss | last post by:
Hi Every one ! I need to insert a set of values which are passed thru the parameter ,Below is the code to do the Single table insertion , Now I need to do multiple table insertion ie, to insert...
by: getmeidea | last post by:
I have the following tables, 1> employee_master(emp_id int primary key, emp_name varchar(100)); 2> employee_salary_payment(salary_rid int primary key, emp_id int, sal_date date, paid_amt int); ...
by: dipalichavan82 | last post by:
i came across a article, where it was mentioned if we want a dynamic querry to fire then use parameterized querry e.g. string inputcity=textbox.text; SqlCommand cmd = new SqlCommand("select * from...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.