perl DBD::mysql::st提取行数组失败:fetch()而不执行execute()于

e5nszbig  于 2022-11-15  发布在  Perl
关注(0)|答案(1)|浏览(170)

我正在访问数据库并使用fetchrow_array()fetchrow_hashref方法,我收到错误:
DBD::mysql::st提取行数组失败:在./ www.example.com的第83行,不使用execute()的fetch()aaa.pl。
我不明白为什么我会得到这个错误,我的工具正在做它应该做的事情,但在我的执行过程中,它给了我这一行。

#!/usr/bin/perl

use DBI;
use strict;

use warnings;
use Switch;
use Data::Dumper;
my $dbType = "mysql";
my $database = "control";
my $host = "localhost";
my $dsn = "";
my $userid = "";
my $password = "";

my $dbDescription = "";
my $dbSa_Query = "";
my $dbttid = "";
my $dbtidv = "";
my $dbti = "";
my $dbrhostfqdn = "";
my $dbDialedNumber = "";
my $dbPortNumber = "";
my $id = 42;
my % carriers;
my % preTranslation;
my % resourceGroup;

sub dataBaseOperation() {

        if ($dbType eq "mysql") {
                #$database = "trustid";
                $dsn = "DBI:$dbType:database=$database;host=$host:port=3306,DBSOCK = '/var/run/mysqld/mysqld.sock'";
                $userid = "XXXX";
                $password = 'XXXX';
        } else {
                $dbType = "postgres";
                $userid = "postgres";
                $password = "postgres";
                $dsn = "DBI:$dbType:database=$database;host=$host:port=5432";
        }

        my $dbcon = DBI -> connect($dsn, $userid, $password) or die "Can't connect to database: $DBI::errstr\n";
        print "connected to the database\n";

        my $notables = $dbcon -> tables();
        print "No of tables : $notables".
        "\n";
        my @tables = $dbcon -> tables(undef, undef, undef, 'TABLE');

        my $len = @tables;
        for (my $i = 0; $i < $len; $i = $i + 1) {
                print("\@tables[$i] = $tables[$i]\n");
                print("\n");
        }
        my $query = 'select * from active_table_set';
        my $sth = $dbcon -> prepare($query) or die "Unable to prepare $query".$dbcon -> errstr;

        $sth -> execute() or die "Unable to execute '$query'.  ".$sth -> errstr;

        while (my @row = $sth -> fetchrow_array()) {
                $database = join(',', @row);
                print($database.
                        "\n");
                if ($dbType eq "mysql") {
                        #$database = "trustid";
                        $dsn = "DBI:$dbType:database=$database;host=$host:port=3306,DBSOCK = '/var/run/mysqld/mysqld.sock'";
                        $userid = "XXXX";
                        $password = 'XXXX';
                } else {
                        $dbType = "postgres";
                        $userid = "postgres";
                        $password = "postgres";
                        $dsn = "DBI:$dbType:database=$database;host=$host:port=5432";
                }
                $dbcon = DBI -> connect($dsn, $userid, $password) or die "Can't connect to database: $DBI::errstr\n";
                print "connected to the database\n";
                @tables = $dbcon -> tables(undef, undef, undef, 'TABLE');
                $len = @tables;
                for (my $i = 0; $i < $len; $i = $i + 1) {
                        print("\@tables[$i] = $tables[$i]\n");
                        print("\n");
                        if ($tables[$i] eq '`trustid_b`.`carriers`') {
                                $sth = $dbcon -> prepare('select * from carriers');

                                $sth -> execute();

                                while (my $row = $sth -> fetchrow_hashref) {
                                        $carriers {
                                                $row -> {
                                                        description
                                                }
                                        } = $row;
                                }
                        }
                }
                @tables = $dbcon -> tables(undef, undef, undef, 'TABLE');
                $len = @tables;
                for (my $i = 0; $i < $len; $i = $i + 1) {
                        if ($tables[$i] eq '`trustid_b`.`pre_translation`') {
                                $sth = $dbcon -> prepare('select * from pre_translation');

                                $sth -> execute();
                                while (my $row = $sth -> fetchrow_hashref) {
                                        $preTranslation {
                                                $row -> {
                                                        id
                                                }
                                        } = $row;
                                }
                        }
                }

                @tables = $dbcon -> tables(undef, undef, undef, 'TABLE');
                $len = @tables;
                for (my $i = 0; $i < $len; $i = $i + 1) {
                        if ($tables[$i] eq '`trustid_b`.`resource_group`') {
                                $sth = $dbcon -> prepare('select * from resource_group');

                                $sth -> execute();
                                while (my $row = $sth -> fetchrow_hashref) {
                                        $resourceGroup {
                                                $row -> {
                                                        description
                                                }
                                        } = $row;
                                }
                        }
                }

                $dbcon -> disconnect;
        }
        $dbcon -> disconnect;
        print("\n".
                "Starting Database Operations.".
                "\n");
        dataBaseXLCompare();
        print "\n";

}

我试过打印它并杀死它,但似乎没有任何工作。
出错的行号--〉

while (my @row = $sth -> fetchrow_array()) {

为什么我使用两个连接,因为它给我正确的输出。我认为一个数据库信息是另一个数据库的表。我没有数据库的信息。我已经使用我的代码访问它,旨在打开载体,预翻译和资源表。这是因为下面的图像。x1c 0d1x

py49o6xq

py49o6xq1#

进入while循环后,它将根据代码对其进行处理。在第二次迭代期间,它将尝试使用fetchrow_array()方法获取另一行,这将导致此错误。
add,last刚好在while循环结束之前,这样循环就不会被迭代。

last;

相关问题