为什么我准备错误?

时间:2014-11-03 08:30:57

标签: perl

#!/usr/bin/perl

use strict;

use Sybase::DBlib;

use Sys::Hostname;
use Getopt::Std;

## additionals
use lib "/opt/chsdjg/perllib";
use ADDITIONALS;

  my ($dsn, $database, $dbserver, $dbname, $user, $passwd, $rmdb_config ) = ('','','','','','','');

  my $dbhandle;
  $rmdb_config  = "$ENV{ENV_DIR}";
  $dsn          = "dbi:Sybase";
  $database     = join (' ~ ',$dsn, $dbserver, $dbname, $user, $passwd, $rmdb_config);
  $dbhandle     = connect_me($database);

  my $ctl= "select * from table_name";
 
  $dbhandle->dbcmd($ctl);
  my $ret = $dbhandle->dbsqlexec;
  my $res = $dbhandle->dbresults;

  
 my @dat;
   while($dbhandle->dbresults != NO_MORE_RESULTS) {
        while(@dat = $dbhandle->dbnextrow) {
  print "@dat\n";
}
}

我第一次没有使用正确的连接。这是现在的代码,它生成一个select语句并显示结果。希望它能帮到人们。

1 个答案:

答案 0 :(得分:2)

您永远不会创建数据库句柄($ dbh未定义)。

添加

my $dbh = $dbh = DBI->connect($data_source, $username, $password)
            or die $DBI::errstr;

给你的代码。有关详细信息,请参阅CPAN上的Documentation