473,379 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Multiple insertion querry

Hello,
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 3177
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, ...)
HTH
PS. I'm more used to writing query :)

--
..sig
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
contain:

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

Cheers,
NC
Jul 17 '05 #3

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

Similar topics

3
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...
0
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...
20
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...
0
by: gabe_pu | last post by:
List Box Multiple Selections I have a list box on my page and I´m trying to add new items on it. The insert operation must be under the selected item. When I make the insertion it is done ...
5
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 ...
9
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...
2
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...
0
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); ...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.