1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/perl
use strict;use warnings;
use IO::Socket;
use DBI;
sub connect_bdd(){
my $dbh = DBI->connect("dbi:Oracle:host=localhost;sid=XE",
'MAXIME','123456', {RaiseError => 1, AutoCommit => 1})
or die "Can't connect to database $DBI::errstr\n";
return $dbh;
}
sub exec_requete(){
my $dbh=$_[0];
my $id=$_[1];
my $name=$_[2];
chomp($name);
my $req=$dbh->prepare("insert into employe (no_emp,name) values($id,'$name')");
$req->execute;
}
sub disconnect_bdd(){
$_[0]->disconnect;
}
my $socket = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => "127.0.0.1",
PeerPort => 30001)
or die "Failed : $@\n";
my $dbh=connect_bdd();
print "*** Debut de connexion ***\n";
my$i=0;
my $reponse;
while($reponse=<$socket>){
if(length($reponse)==512){
&exec_requete($dbh,$i,$reponse);
#my $message =<STDIN>;
#print $socket "ajz\n";
$i++;
}
}
&disconnect_bdd($dbh);
print "*** Fin de connexion ***\n";
__END__ |
Partager