Thread SQL Statement aus Text Datei lesen (3 answers)
Opened by tophoven at 2008-03-22 21:01

renee
 2008-03-23 00:43
#107386 #107386
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code (perl): (dl )
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;


test.sql:
Code: (dl )
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');
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread SQL Statement aus Text Datei lesen