我想在数据库中插入多行,但我只插入了一行或插入了缺少的行
我的sql表结构:
CREATE TABLE `test`
(
`ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`time` datetime NOT NULL,
`nb_osuser` int NOT NULL,
`osuser_name` nvarchar(100)NOT NULL,
`program` nvarchar(100)NOT NULL,
`last_line` nvarchar(100)NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY (`time`)
) ENGINE=InnoDB;
插入查询:
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=database;host=IP",
"hostname", 'password',
{'RaiseError' => 1});
while (my ($user, $ref) = each %counts) {
while (my ($program, $count) = each %$ref) {
#print "$count OSUSER with session $user and with program $program\n";
print "time = $time, count = $count, user = $user, program = $program, last_line = $last_line\n";
$request ="'$time', '$count', '$user', '$program', $last_line";
my $sth = $dbh->prepare("REPLACE `test` (time, nb, os_name, program, last_line) VALUES($request);")
}
}
我的表中的数据:
ID USER TERMINAL SERVICE
---------- ------------------------- --------------- -------------------------
1 toto titi roro
2 toto titi roro
4 gigi gege fefe
我想要:
+----+---------------------+-----------+-------------+----------------+-----------+
| ID | time | nb | os_name | program | last_line |
+----+---------------------+-----------+-------------+----------------+-----------+
| 15 | 2019-01-04 14:00:00| 33 | titi | roro | 109 |
| 16 | 2019-01-04 14:00:00| 9 | gege | fefe | 109 |
谢谢你提供任何信息
暂无答案!
目前还没有任何答案,快来回答吧!