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
|
#!/usr/bin/perl -w
######### Libraries that we need ############
use lib "/export/home/glasap/bin/perl/lib";
use strict;
use DBI();
#############################################
# constructor
sub new
{
my ($classe, $host, $login, $passwd, $bdd) = @_;
my $this = {"host" => $host,"login" => $login, "passwd" => $passwd, "bdd" => $bdd};
bless ($this,$classe);
return $this;
}
# Destructor
sub DESTROY
{
print "Destruction de l'objet";
}
# database connection
sub connect
{
my ($this, $cnx) = @_;
$cnx = DBI->connect("DBI:mysql:database=".$this->{bdd}.";host=".$this->{host}.", ".$this->{login}.", ".$this->{passwd}.", {'RaiseError' => 1}") || die("Bad connection");
bless($this,$cnx);
}
# Database deconnection
sud deconnect
{
my ($dbh);
$dbh->disconnect;
}
# Query execution
sub exec
{
my ($this, $sth, $sql) = @_;
$sth=$dbh->prepare($sql);
$sth->execute();
} |
Partager