473,890 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert multiple rows at once

Hello there,

i have a strange problem. I can't get php to insert multiple rows at once in
a MySQL database. I use the
$sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',
'$e')";

I want to insert 5 rows at a time in the database, but it only inserts every
5th record. For example:
1. AA
2. AB
3. AC
4. AD
5. AE

I only find 5. AE back in the mysql with id 1.

How can I insert multiple rows at once ???

Thnx in advance

RotterdamStuden ts.
Jul 17 '05 #1
7 33321
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStuden ts wrote:
Hello there,

i have a strange problem. I can't get php to insert multiple rows at once in
a MySQL database. I use the
$sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',
'$e')";

These are columns, not rows.

I want to insert 5 rows at a time in the database, but it only inserts every
5th record. For example:
1. AA
2. AB
3. AC
4. AD
5. AE

I only find 5. AE back in the mysql with id 1.

How can I insert multiple rows at once ???

Thnx in advance

RotterdamStuden ts.

AFAIK, they have to be inserted separately with multiple SQL statements.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
.oO(Ian.H)
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStuden ts wrote:
How can I insert multiple rows at once ???

AFAIK, they have to be inserted separately with multiple SQL statements.


INSERT INTO foo (bar) VALUES ('bar1'), ('bar2'), ('bar3');

Micha
Jul 17 '05 #3
On Mon, 16 Aug 2004 22:19:50 +0100, Michael Fesser wrote:
.oO(Ian.H)
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStuden ts wrote:
How can I insert multiple rows at once ???

AFAIK, they have to be inserted separately with multiple SQL statements.


INSERT INTO foo (bar) VALUES ('bar1'), ('bar2'), ('bar3');

Micha

ahah!

Thanks Micha.. this'll help me too =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #4
"RotterdamStude nts" wrote:
Hello there,

i have a strange problem. I can’t get php to insert multiple
rows at once in
a MySQL database. I use the
$sql = "INSERT INTO database (a,b,c,d,e) VALUES (’$a’,
’$b’ ,’$c’, ’$d’,
’$e’)";

I want to insert 5 rows at a time in the database, but it only inserts every
5th record. For example:
1. AA
2. AB
3. AC
4. AD
5. AE

I only find 5. AE back in the mysql with id 1.

How can I insert multiple rows at once ???

Thnx in advance

RotterdamStuden ts.


http://www.desilva.biz/mysql/insert.html

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Insert-m...ict140156.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=468729
Jul 17 '05 #5
On Mon, 16 Aug 2004 22:19:50 +0100, Michael Fesser <ne*****@gmx.ne t> wrote:
.oO(Ian.H)
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStuden ts wrote:
How can I insert multiple rows at once ???

AFAIK, they have to be inserted separately with multiple SQL statements.


INSERT INTO foo (bar) VALUES ('bar1'), ('bar2'), ('bar3');


Although watch out as MySQL doesn't have any way of indicating which of the
rows caused an error, if there is one partway through.

And it's got some plain wrong behaviour as well:

mysql> insert into x values (null);
ERROR 1048: Column 'c' cannot be null

mysql> insert into x values ('aa'), (null);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from x where c is null;
Empty set (0.00 sec)

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6
.oO(Andy Hassall)
And it's got some plain wrong behaviour as well:

mysql> insert into x values (null);
ERROR 1048: Column 'c' cannot be null

mysql> insert into x values ('aa'), (null);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0


This returns a warning on my system, but MySQL inserts an empty value
instead of the default value:

mysql> DESC foo;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| bar | varchar(10) | | | bar | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> INSERT INTO foo VALUES ('test'), (NULL);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 1

mysql> SELECT * FROM foo;
+------+
| bar |
+------+
| test |
| |
+------+
2 rows in set (0.00 sec)

Micha
Jul 17 '05 #7
> http://www.desilva.biz/mysql/insert.html

--

Thanks this works.

RotterdamStuden ts
Jul 17 '05 #8

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

Similar topics

1
26487
by: Tuhin Kumar | last post by:
Hi, I would like to know how to insert multiple rows into a table, using a single INSERT statement. My requirement is like this I have a table ABC which contains multiple employees entries with empId as the primary key. Now I want to insert the all the empid multiplied by X and y (<EMPID>*x*y) into a table DEF plus filling other columns for each employee rows. Table ABC --------- EMPID QQQ LLL MMM
3
3042
by: Jason | last post by:
The best way to explain this is by example. I have a source table with many columns. Source SYMBOL EXCHANGE_NAME CUSIP TYPE ISSUE_NAME
10
3412
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void AddMinimunWageStipen(string payrollid,double amount) { System.Data.SqlClient.SqlConnection cn = null; System.Data.SqlClient.SqlCommand cm = null;
3
6348
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an older version that I am updating. Thus I get this message. It tells me only how many records have errors, not which errors or which records. Anyone have a nice solution to identifying the specific records involved? Maybe even the specific...
2
3693
by: wombat53 | last post by:
Hi Group Are there any DB2 UDB ESE DPF V8.2 users exploiting "buffered inserts" (BIND parm INSERT BUF) *and* "multi-row INSERTS" (many rows associated with the VALUES clause of the INSERT to minimize number of calls to the RDMBS engine) in an SQL PL Stored Procedure? I ask, as the latter would imply embedded DYNAMIC SQL due to potentially varying number of rows to be inserted (assume it's varying), and so, the SQL INSERT would have be...
4
2923
by: Michel Esber | last post by:
Hello, Environment: db2 V8 FP 13 LUW Our application currently uses: insert into table values ('A'),('B'),...('Z') We have used CLI arrays inserts (1000 array and commit size) and managed to insert 1 Million rows into an empty table in 32 seconds. Our
20
188395
by: talktozee | last post by:
Hey, everyone! Basically, I need to insert *multiple rows* into table A from table B based upon some criteria, and I need to insert some static values along with each row from table A. For example: insert into tableA (col1,col2,col3,col4,col5) values ('Cheese', 'Blue',
24
7163
by: Henry J. | last post by:
My app needs to insert thousand value rows into a mostly empty table (data are read from a file). I can either use inserts, or use merge. The advantage of using merge is that in the few cases where the table is not empty, it can take care of the updating part, which makes the app cleaner. However, my concern is the merge state would slow dowm the insertion of new data, since in most cases the table is empty. So my questions (before I...
58
8168
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also the parts section an i seem to be having trouble. When i try to insert into the parts section i get the error Invalid character value for cast specification. But not sure what i am doing wrong. Here is what i am using to insert. All the sections...
0
11222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4674
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3275
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.