4 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl use strict; use warnings; use DBI; my $file = 'test.sql'; my $dbh = DBI->connect( ... ) or die $DBI::errstr; open my $fh, '<', $file or die $!; { local $/ = "\n\n"; while( my $statement = <$fh> ){ my $sth = $dbh->prepare( $statement ) or die $dbh->errstr; $sth->execute or die $dbh->errrstr; } } close $fh;
1
2
3
4
5
6
CREATE TABLE testtbl (
ID int not null primary key,
Testcol VARCHAR(255)
);
INSERT INTO testtbl(ID,Testcol) VALUES(1,'Hallo');
1 2 3 4 5 6
use DBI; my $dbh = DBI->connect('DBI:mysql:database=foobar', 'nobody', 'secret password'); { local $/ = ';'; while (my $sql = <>) { $dbh->do($sql); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
my $FH; unless( open( $FH, '<', $sqlFile ) ) { die "Error: can't open file '$sqlFile': $!\n"; } else { local $/ = ';'; while( my $statement = <$FH> ) { chomp( $statement ); my $sth = $dbh->prepare( $statement ) or die "Error in prepare: " . $dbh->errstr; $sth->execute() or die "Error in excute: " . $dbh->errstr; } # while $statement close( $FH ) or die "Error at closing file '$sqlFile': $!\n"; }
4 Einträge, 1 Seite |