Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1277901
  • 博文数量: 213
  • 博客积分: 7590
  • 博客等级: 少将
  • 技术积分: 2185
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-31 17:31
个人简介

热爱开源,热爱linux

文章分类

全部博文(213)

文章存档

2018年(4)

2017年(1)

2015年(1)

2014年(5)

2013年(2)

2012年(2)

2011年(21)

2010年(82)

2009年(72)

2008年(23)

分类: Mysql/postgreSQL

2011-04-02 17:00:26

  1. #!/usr/bin/perl -w

  2. #The script is used to connect mysql and show table members of the
  3. #database library
  4. use DBI();
  5. $datetime=$ARGV[0];
  6. $event=$ARGV[1];
  7. $path=$ARGV[2];
  8. #connect
  9. my $dbh = DBI->connect("DBI:mysql:database=log;host=localhost","root","ceagle",
  10.         {'RaiseError'=>1,'AutoCommit'=>0});

  11. #execute query
  12. #my $sth = $dbh->prepare("SELECT * from members");
  13. #$sth->execute();
  14. eval
  15. {
  16.     #insert data to members
  17.         $dbh->do("insert into loginfo values (NULL,'$datetime','$event','$path')");
  18.         $dbh->commit();

  19. };
  20. #iterate through resultset
  21. my $sth = $dbh->prepare("SELECT * from loginfo");

  22. $sth->execute();
  23. print "id\t\tdatetime\tevent\tpath","\n";
  24. while (my $ref = $sth->fetchrow_hashref()) {
  25.   print "$ref->{'logid'}\t\t$ref->{'datetime'}\t$ref->{'event'}\t$ref->{'path'}\n";
  26. }

  27. #Delete the data
  28. #eval
  29. #{
  30. #    $dbh->do("delete from members where fname = 'cao' ");
  31. #    $dbh->commit();
  32. #
  33. #};
  34. if ($@){
  35.     print "Transaction aborted:$@";
  36.     $dbh->rollback();
  37. }
  38. #clean up
  39. $sth->finish();
  40. $dbh->disconnect();
阅读(1022) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~