- 论坛徽章:
- 0
|
- #!/usr/bin/perl -w
-
-
#The script is used to connect mysql and show table members of the
-
#database library
-
use DBI();
-
$datetime=$ARGV[0];
-
$event=$ARGV[1];
-
$path=$ARGV[2];
-
#connect
-
my $dbh = DBI->connect("DBI:mysql:database=log;host=localhost","root","ceagle",
-
{'RaiseError'=>1,'AutoCommit'=>0});
-
-
#execute query
-
#my $sth = $dbh->prepare("SELECT * from members");
-
#$sth->execute();
-
eval
-
{
-
#insert data to members
-
$dbh->do("insert into loginfo values (NULL,'$datetime','$event','$path')");
-
$dbh->commit();
-
-
};
-
#iterate through resultset
-
my $sth = $dbh->prepare("SELECT * from loginfo");
-
-
$sth->execute();
-
print "id\t\tdatetime\tevent\tpath","\n";
-
while (my $ref = $sth->fetchrow_hashref()) {
-
print "$ref->{'logid'}\t\t$ref->{'datetime'}\t$ref->{'event'}\t$ref->{'path'}\n";
-
}
-
-
#Delete the data
-
#eval
-
#{
-
# $dbh->do("delete from members where fname = 'cao' ");
-
# $dbh->commit();
-
#
-
#};
-
if ($@){
-
print "Transaction aborted:$@";
-
$dbh->rollback();
-
}
-
#clean up
-
$sth->finish();
-
$dbh->disconnect();
|
|