in reply to SQL statement produces no results when executed using DBI's prepared statement, but one record when executed directly in MySQL. WHY?

From the doc:

              fetchrow_arrayref. Fetches the next row of data and returns it as a list containing the field values.

In your assignment:

$aref = $sth->fetchrow_array;
You are assigning a list to a scalar. i.e. $aref is a SCALAR .

The next statement, you try to dereference $aref as an array ref.

If you had use warnings; it would say:

       Useless use of a constant (..) in void context at ...

In any case, @$aref is empty.

It would also be helpful to do error checking (RaiseError, or check $sth->err).

If you are confident that the fetchrow_array returns a value, try:

($aref )= $sth->fetchrow_array; print "GOT |$aref|\n";
Update:Corrected doc reference from fetchrow_arrayref to fetchrow_array. Thanks McA for pointing this out.

        Profanity is the one language all programmers know best.

  • Comment on Re: SQL statement produces no results when executed using DBI's prepared statement, but one record when executed directly in MySQL. WHY?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: SQL statement produces no results when executed using DBI's prepared statement, but one record when executed directly in MySQL. WHY?
by ted.byers (Monk) on Aug 07, 2014 at 15:10 UTC

    Thanks

    My error was to use fetchrow_array instead of fetchrow_arrayref (which is what, in fact, I'd intended). Making that change fixed all.

    Just goes to show that trying to code when you're over-tired is not conducive to being productive, allowing silly errors to creep in. Nor is it conducive to remaining sane. :-(

    Thanks

    Ted