服务器 频道

perl DBI模块举例

  【IT168 服务器学院】在perl语言中使用DBI连接数据库:

  连接MYSQL:
  my  $dbh=DBI->connect(''DBI:mysql:database=mddb;host=*.*.*.*;port=8848'',''mysql'',''mysql'', {Rais
  eError => 0,PrintError => 0, AutoCommit => 1 });

  my $sql = qq{ SELECT count(*) FROM tpd_unic_bts where scan_start_time=\"$scan_start\" and omc_id=$om
  c_id;};
  my $sth = $dbh->prepare( $sql ) or die "Can''t prepare $sql";
  $sth->execute();

  my( $count );
  $sth->bind_columns( undef, \$count);
  while( $sth->fetch() ){
          print "$count\n";
                        }
  $sth->finish();
  $dbh->disconnect();
  连接Informix:
  my $dbh = DBI->connect( ''DBI:Informix:npmdb'', ''informix'', ''informix'' ) || die "Database connection n
  ot made: $DBI::errstr";

  操作方式同mddb

0
相关文章