1

I'm working on a script called "hlstats.pl" which is a stats server from Half-Life game from http://www.hlstats-community.org/

I'm trying to run this on Strawberry perl on Windows with MySQL.

I've isolated the issue to fetchrow_array only returning whatever the last column is in the query.
Here is my modified code snippet from 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();

It will print out all the values in the column "value" if it's last and I can reverse it and it will print all the values in the "keyname" column if I move those around in the query. It's not clear to me why we aren't receiving back all the columns.

This is perl, v5.10.0 built for MSWin32-x86-multi-thread

MySQL version 5.7.10

"perldoc perllocal" output

  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;

The output is:

  • DBM
  • ExampleP
  • File
  • Gofer
  • Multiplex
  • Proxy
  • SQLite
  • Sponge
  • mysql
5
  • Can you try to change the SELECT query to something like: SELECT 111 AS keyname, 222 AS value to see if it will have the same issue. After that, it would also be possible for you to provide a self contained program that exhibits the issue, since there will be no reference to your actual tables. Commented Sep 16, 2016 at 17:17
  • 1
    You say in the question that the code provided is "modified" from the original program. Double-check that, in the actual program, you really do have @row = $result->fetchrow_array. The problem you describe sounds like what would happen if you accidentally wrote $row = $result->fetchrow_array instead. Commented Sep 16, 2016 at 18:35
  • Forgive me I'm struggling with the Perl. Thank goodness for stackoverflow already! My understanding is that @row is an array because it's defined with an @ instead of a $. So wouldn't the statement: @row = $result->fetchrow_array() Assign the array result to the array variable? Commented Sep 16, 2016 at 18:37
  • @tjd, fetchrow_array is being called in list context Commented Sep 16, 2016 at 20:05
  • Re "Here is my modified code snippet from hlstats.pl", No good. Provide us code that actually exhibits the problem. Commented Sep 16, 2016 at 20:06

1 Answer 1

1

It is highly likely that your real code has this

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

    foreach $field ( $row ) {

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

The documentation for fetchrow_array says this

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.

I would write this

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

or you can use fetchrow_arrayref like this

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

It can be very hard to uncover a bug when we can't see what you see. Please be careful either to show the real source code, or something that you have tested and produces the same symptom.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.