gpt4 book ai didi

mysql - perl fetchrow_array 只返回最后一列而不是所有列

转载 作者:行者123 更新时间:2023-11-28 23:25:35 27 4
gpt4 key购买 nike

我正在编写一个名为“hlstats.pl”的脚本,它是来自 http://www.hlstats-community.org/ 的半条命游戏的统计服务器

我正在尝试使用 MySQL 在 Windows 上的 Strawberry perl 上运行它。

我已将问题隔离到 fetchrow_array,只返回查询中的最后一列。
这是我从 hlstats.pl 修改后的代码片段

# load the options from DB
my $result = &doQuery("SELECT keyname, value FROM `${db_prefix}_Options`");
my @row;
while (@row = $result->fetchrow_array()) {
foreach $field (@row) {
if (defined($field)) {
print "$field\n";
} else {
print "<NULL>\n";
}
}
}
##my ($keyname, $value, %oHash);
##while( ($keyname, $value) = $result->fetchrow_array ) {
## # $oHash{$keyname} = $value;
## print $keyname;
## print "\n";
##}
$result->finish();

如果它是最后一个,它会打印出“值”列中的所有值,我可以反转它,它会打印所有“键名”列中的值,如果我在查询中移动这些值。我不清楚为什么我们没有收到所有的专栏。

这是为 MSWin32-x86-多线程构建的 perl,v5.10.0

MySQL 版本 5.7.10

“perldoc perllocal”输出

  Thu Jan 29 21:17:27 2009: "Module" ExtUtils::MakeMaker
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 6.48"

* "EXE_FILES: bin/instmodsh"

Thu Jan 29 21:17:32 2009: "Module" File::Path
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.07"

* "EXE_FILES: "

Thu Jan 29 21:17:38 2009: "Module" ExtUtils::Command
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.16"

* "EXE_FILES: "

Thu Jan 29 21:17:47 2009: "Module" Win32API::File
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.1101"

* "EXE_FILES: "

Thu Jan 29 21:18:05 2009: "Module" ExtUtils::Install
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.52"

* "EXE_FILES: "

Thu Jan 29 21:18:10 2009: "Module" ExtUtils::Manifest
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.56"

* "EXE_FILES: "

Thu Jan 29 21:18:34 2009: "Module" Test::Harness
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 3.14"

* "EXE_FILES: bin/prove"

Thu Jan 29 21:18:43 2009: "Module" Test::Simple
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.86"

* "EXE_FILES: "

Thu Jan 29 21:18:48 2009: "Module" ExtUtils::CBuilder
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.24"

* "EXE_FILES: "

Thu Jan 29 21:18:54 2009: "Module" ExtUtils::ParseXS
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.19"

* "EXE_FILES: "

Thu Jan 29 21:19:05 2009: "Module" version
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.76"

* "EXE_FILES: "

Thu Jan 29 21:19:11 2009: "Module" IO::Compress::Base
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.015"

* "EXE_FILES: "

Thu Jan 29 21:19:23 2009: "Module" Compress::Raw::Zlib
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.015"

* "EXE_FILES: "

Thu Jan 29 21:19:33 2009: "Module" Compress::Raw::Bzip2
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.015"

* "EXE_FILES: "

Thu Jan 29 21:20:34 2009: "Module" IO::Compress::Zlib
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.015"

* "EXE_FILES: "

Thu Jan 29 21:20:47 2009: "Module" IO::Compress::Bzip2
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.015"

* "EXE_FILES: "

Thu Jan 29 21:20:55 2009: "Module" Compress::Zlib
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.015"

* "EXE_FILES: "

Thu Jan 29 21:21:18 2009: "Module" Compress::Bzip2
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.09"

* "EXE_FILES: "

Thu Jan 29 21:21:24 2009: "Module" IO::Zlib
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.09"

* "EXE_FILES: "

Thu Jan 29 21:21:31 2009: "Module" Cwd
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 3.29"

* "EXE_FILES: "

Thu Jan 29 21:21:53 2009: "Module" File::Temp
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.21"

* "EXE_FILES: "

Thu Jan 29 21:22:03 2009: "Module" Win32::WinError
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.03"

* "EXE_FILES: "

Thu Jan 29 21:22:14 2009: "Module" Win32API::Registry
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.30"

* "EXE_FILES: "

Thu Jan 29 21:22:19 2009: "Module" Win32::TieRegistry
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.25"

* "EXE_FILES: "

Thu Jan 29 21:22:24 2009: "Module" File::HomeDir
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.82"

* "EXE_FILES: "

Thu Jan 29 21:22:29 2009: "Module" File::Which
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.05"

* "EXE_FILES: bin/pwhich"

Thu Jan 29 21:22:42 2009: "Module" Archive::Zip
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.26"

* "EXE_FILES: bin/crc32"

Thu Jan 29 21:22:46 2009: "Module" Package::Constants
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.02"

* "EXE_FILES: "

Thu Jan 29 21:22:51 2009: "Module" IO::String
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.08"

* "EXE_FILES: "

Thu Jan 29 21:22:59 2009: "Module" Archive::Tar
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.44"

* "EXE_FILES: bin/ptar bin/ptardiff"

Thu Jan 29 21:23:04 2009: "Module" Parse::CPAN::Meta
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.04"

* "EXE_FILES: "

Thu Jan 29 21:23:16 2009: "Module" YAML
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.68"

* "EXE_FILES: "

Thu Jan 29 21:23:23 2009: "Module" Digest::MD5
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.38"

* "EXE_FILES: "

Thu Jan 29 21:23:29 2009: "Module" Digest::SHA1
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.11"

* "EXE_FILES: "

Thu Jan 29 21:23:38 2009: "Module" Digest::SHA
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 5.47"

* "EXE_FILES: shasum"

Thu Jan 29 21:25:58 2009: "Module" CPAN
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.9301"

* "EXE_FILES: scripts/cpan"

Thu Jan 29 21:26:05 2009: "Module" Term::ReadKey
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.30"

* "EXE_FILES: "

Thu Jan 29 21:26:09 2009: "Module" Term::ReadLine
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.0302"

* "EXE_FILES: "

Thu Jan 29 21:26:13 2009: "Module" Text::Glob
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.08"

* "EXE_FILES: "

Thu Jan 29 21:26:24 2009: "Module" URI
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.37"

* "EXE_FILES: "

Thu Jan 29 21:26:28 2009: "Module" HTML::Tagset
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 3.20"

* "EXE_FILES: "

Thu Jan 29 21:26:41 2009: "Module" HTML::Parser
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 3.59"

* "EXE_FILES: "

Thu Jan 29 21:27:18 2009: "Module" LWP
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 5.823"

* "EXE_FILES: bin/lwp-request bin/lwp-mirror bin/lwp-rget
bin/lwp-download"

Thu Jan 29 21:27:31 2009: "Module" LWP::Online
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.07"

* "EXE_FILES: "

Thu Jan 29 21:27:56 2009: "Module" Win32::File
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.06"

* "EXE_FILES: "

Thu Jan 29 21:28:17 2009: "Module" File::Remove
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.42"

* "EXE_FILES: "

Thu Jan 29 21:28:21 2009: "Module" Win32::File::Object
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.01"

* "EXE_FILES: "

Thu Jan 29 21:28:45 2009: "Module" Win32::API
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.58"

* "EXE_FILES: "

Thu Jan 29 21:29:05 2009: "Module" Params::Util
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.35"

* "EXE_FILES: "

Thu Jan 29 21:29:14 2009: "Module" IPC::Run3
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.042"

* "EXE_FILES: "

Thu Jan 29 21:29:19 2009: "Module" Test::Script
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.03"

* "EXE_FILES: "

Thu Jan 29 21:29:24 2009: "Module" Win32::Env::Path
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.01"

* "EXE_FILES: script/win32envpath"

Thu Jan 29 21:29:46 2009: "Module" Parse::Binary
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.11"

* "EXE_FILES: "

Thu Jan 29 21:29:51 2009: "Module" Win32::Exe
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.11"

* "EXE_FILES: script/exe_update.pl"

Thu Jan 29 21:30:32 2009: "Module" Math::BigInt
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.89"

* "EXE_FILES: "

Thu Jan 29 21:30:52 2009: "Module" Math::BigInt::FastCalc
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.19"

* "EXE_FILES: "

Thu Jan 29 21:31:14 2009: "Module" Math::BigRat
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.22"

* "EXE_FILES: "

Thu Jan 29 21:31:37 2009: "Module" Math::BigInt::GMP
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.24"

* "EXE_FILES: "

Thu Jan 29 21:31:49 2009: "Module" XML::Parser
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.36"

* "EXE_FILES: "

Thu Jan 29 21:32:18 2009: "Module" XML::NamespaceSupport
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.09"

* "EXE_FILES: "

Thu Jan 29 21:32:28 2009: "Module" XML::SAX
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.96"

* "EXE_FILES: "

Thu Jan 29 21:32:41 2009: "Module" XML::LibXML::Common
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.13"

* "EXE_FILES: "

Thu Jan 29 21:33:01 2009: "Module" XML::LibXML
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.69"

* "EXE_FILES: "

Thu Jan 29 21:33:30 2009: "Module" PAR::Dist
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.43"

* "EXE_FILES: "

Thu Jan 29 21:33:37 2009: "Module" PAR::Dist::FromPPD
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.03"

* "EXE_FILES: bin/ppd2par"

Thu Jan 29 21:33:42 2009: "Module" PAR::Dist::InstallPPD
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.02"

* "EXE_FILES: bin/parinstallppd"

Thu Jan 29 21:34:18 2009: "Module" IO::Stringy
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.110"

* "EXE_FILES: "

Thu Jan 29 21:34:41 2009: "Module" Tree::DAG_Node
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.06"

* "EXE_FILES: "

Thu Jan 29 21:35:03 2009: "Module" Test::Warn
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.11"

* "EXE_FILES: "

Thu Jan 29 21:35:21 2009: "Module" Test::Tester
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.107"

* "EXE_FILES: "

Thu Jan 29 21:35:27 2009: "Module" Test::NoWarnings
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.084"

* "EXE_FILES: "

Thu Jan 29 21:35:34 2009: "Module" Test::Deep
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.103"

* "EXE_FILES: "

Thu Jan 29 21:35:39 2009: "Module" DBM::Deep
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.0013"

* "EXE_FILES: "

Thu Jan 29 21:35:59 2009: "Module" YAML::Tiny
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.36"

* "EXE_FILES: "

Thu Jan 29 21:36:23 2009: "Module" AutoLoader
* "installed into: C:\strawberry\perl\lib"

* "LINKTYPE: dynamic"

* "VERSION: 5.68"

* "EXE_FILES: "

Thu Jan 29 21:36:29 2009: "Module" PAR
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.984"

* "EXE_FILES: "

Thu Jan 29 21:36:34 2009: "Module" PAR::Repository::Query
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.12"

* "EXE_FILES: "

Thu Jan 29 21:36:39 2009: "Module" PAR::Repository::Client
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.21"

* "EXE_FILES: "

Thu Jan 29 21:36:49 2009: "Module" PPM
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.01_01"

* "EXE_FILES: bin/ppm.pl"

Thu Jan 29 21:37:09 2009: "Module" Number::Compare
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.01"

* "EXE_FILES: "

Thu Jan 29 21:37:19 2009: "Module" pler
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.34"

* "EXE_FILES: script/pler"

Thu Jan 29 21:37:44 2009: "Module" Data::Compare
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.21"

* "EXE_FILES: "

Thu Jan 29 21:37:50 2009: "Module" CPAN::Checksums
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 2.02"

* "EXE_FILES: "

Thu Jan 29 21:37:56 2009: "Module" File::chmod
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.32"

* "EXE_FILES: "

Thu Jan 29 21:38:01 2009: "Module" CPAN::Inject
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.11"

* "EXE_FILES: script/cpaninject"

Thu Jan 29 21:38:15 2009: "Module" pip
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.13"

* "EXE_FILES: script/pip"

Thu Jan 29 21:39:33 2009: "Module" DBI
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.607"

* "EXE_FILES: dbiproxy dbiprof dbilogstrip"

Thu Jan 29 21:40:00 2009: "Module" DBD::SQLite
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 1.14"

* "EXE_FILES: "

Thu Jan 29 21:40:20 2009: "Module" CPAN::DistnameInfo
* "installed into: C:\strawberry\perl\site\lib"

* "LINKTYPE: dynamic"

* "VERSION: 0.07"

* "EXE_FILES: "

use strict;
use warnings;

use DBI;

print map "$_\n",
DBI->available_drivers;

输出是:

  • 数据库管理
  • 例子P
  • 文件
  • 打野
  • 多路复用
  • 代理
  • SQLite
  • 海绵
  • 数据库

最佳答案

很有可能你的真实代码有这个

while ( $row = $result->fetchrow_array() ) {

foreach $field ( $row ) {

if ( defined($field) ) {
print "$field\n";
}
else {
print "<NULL>\n";
}
}
}

documentation for fetchrow_array说这个

If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that.

我会写这个

while ( my @row = $result->fetchrow_array ) {
print "$_\n" for map { $_ // '<NULL>' } @row;
}

或者你可以像这样使用fetchrow_arrayref

while ( my $row = $result->fetchrow_arrayref ) {
print "$_\n" for map { $_ // '<NULL>' } @$row;
}

当我们看不到您所看到的内容时,可能很难发现错误。请小心显示真正的源代码,或者您已经测试并产生相同症状的东西。

关于mysql - perl fetchrow_array 只返回最后一列而不是所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39536826/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com