Hromadné operace s DBI
Skočit na navigaci
Skočit na vyhledávání
use DBI; my $dbh = DBI->connect("dbi:Pg:dbname=postgres;host=localhost","",""); $dbh->do("drop table if exists xxx"); $dbh->do("create table xxx (a int, b varchar, c varchar, d date, e numeric)"); my $i; my $sql; $sql = "insert into xxx values (?,?,?,?,?)"; my $stmt = $dbh->prepare($sql); my (@data1, @data2, @data3, @data4, @data5); for ($i = 0; $i < 10; $i++) { $data1[$i] = $i; $data2[$i] = "this is a char thirty"; $data3[$i] = "this is a varchar 255"; $data4[$i] = "2002-08-01 11:12:13.123"; $data5[$i] = $i * 1.1; } $stmt->bind_param_array(1, \@data1); $stmt->bind_param_array(2, \@data2); $stmt->bind_param_array(3, \@data3); $stmt->bind_param_array(4, \@data4); $stmt->bind_param_array(5, \@data5); $data2 = "this is a char thirty"; $data3 = "this is a varchar 255"; $data4 = "2002-08-01 11:12:13.123"; my %status; for ($i = 1; $i <= 2; $i++) { $data5 = $i * 1.1; $stmt->execute_array(\%status); } $dbh->disconnect();