Perl DBI Error Msg: Can't call method “selectcol_arrayref” on an undefined value

后端 未结 3 497
梦毁少年i
梦毁少年i 2021-01-26 14:50
my $dblinks = \'\';
$dblinks = $dbh->selectcol_arrayref(\"select db_link from db_links where ticket=\\\'LOW\\\'\");
my $success = 0;
for my $dblink (@$dblinks) {
  $s         


        
3条回答
  •  一个人的身影
    2021-01-26 15:51

    You don't show where $dbh is assigned. Presumably you do so earlier. If you do not, then I beseech you to add these two litle lines to all your code files:

    use strict;
    use warnings;
    

    ...and they will save you from a world of hurt.

    Earlier on when you create the db handle, you should check if something bad happened:

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

    There is no real point in continuing with your program if you cannot get a db handle, is there? If you don't die, you should at least return from this function/method/area of code that is responsible for handling the DB.

    There other issues with your code, such as using eval {} blocks everywhere and calling functions with &, but this has been covered quite amply in earlier questions on this site so I would encourage you to do a search.

提交回复
热议问题