By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,011 Members | 1,000 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,011 IT Pros & Developers. It's quick & easy.

Insert multiple rows at once

P: n/a
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

RotterdamStudents.
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStudents 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

RotterdamStudents.

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

P: n/a
.oO(Ian.H)
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStudents 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

P: n/a
On Mon, 16 Aug 2004 22:19:50 +0100, Michael Fesser wrote:
.oO(Ian.H)
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStudents 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

P: n/a
"RotterdamStudents" 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

RotterdamStudents.


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

P: n/a
On Mon, 16 Aug 2004 22:19:50 +0100, Michael Fesser <ne*****@gmx.net> wrote:
.oO(Ian.H)
On Mon, 16 Aug 2004 21:32:45 +0200, RotterdamStudents 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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6

P: n/a
.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

P: n/a
> http://www.desilva.biz/mysql/insert.html

--

Thanks this works.

RotterdamStudents
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.