Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4166099
  • 博文数量: 291
  • 博客积分: 8003
  • 博客等级: 大校
  • 技术积分: 4275
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-30 18:28
文章分类

全部博文(291)

文章存档

2017年(1)

2013年(47)

2012年(115)

2011年(121)

2010年(7)

分类: Python/Ruby

2011-04-23 16:31:08

  1. #!/bin/perl

  2. # load module
  3. use DBI;

  4. # connect
  5. my $dbh = DBI->connect("DBI:mysql:database=db2;host=localhost", "joe", "guessme", {'RaiseError' => 1});

  6. # execute INSERT query
  7. my $rows = $dbh->do("INSERT INTO users (id, username, country) VALUES (4, 'jay', 'CZ')");
  8. print "$rows row(s) affected ";

  9. # execute SELECT query
  10. my $sth = $dbh->prepare("SELECT username, country FROM users");
  11. $sth->execute();

  12. # iterate through resultset
  13. # print values
  14. while(my $ref = $sth->fetchrow_hashref()) {
  15.     print "User: $ref-> ";
  16.     print "Country: $ref-> ";
  17.     print "---------- ";
  18. }

  19. # clean up
  20. $dbh->disconnect();
阅读(4055) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~