ITPub博客

首页 > Linux操作系统 > Linux操作系统 > perl 读mysql 数据 。

perl 读mysql 数据 。

原创 Linux操作系统 作者:season0891 时间:2010-05-28 14:05:09 0 删除 编辑
  3) 测试:
  使用MySQL数据库(使用mSQL也可以)建立一个数据库:abacus,写一个简单的perl程 序:perlmysql.cgi,
  从一个数据库abacus中读出所有的表名并且显示。
  
   #!/usr/bin/perl
  
  use DBI;
  print "Content-type: text/html\n\n";
  print "\n";
  print "\n";
  $driver="mysql";
    $dbh=DBI->connect("DBI:mysql:abacus:mysql.szabacus.com","root","abcde")||die "can
  not connect database";
  $sth=$dbh->prepare("show tables")||die "occur an error when query database";
   $sth->execute();
  $numRows=$sth->rows;
   while(@row=$sth->fetchrow_array)
  {
  print "Table: $row[0]\n";
  }
  print "query lines=$numRows\n";
   $sth->finish();
  $dbh->disconnect();
  exit;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/90618/viewspace-663915/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-06-10

  • 博文量
    790
  • 访问量
    2098071