Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
"SELECT min(id),max(id) from images where gallery_path like '/px6%' +") || die $d->errstr;

should be

"SELECT min(id),max(id) from images where gallery_path like '/px6%' +") or die $d->errstr;

You are forcing the selectrow_array call to be in scalar context by use of the "c-style logical or" || (see the precedence chart in perlop). You need to use or. Quoth the docs:

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. Also, in a scalar context, an "undef" is returned if there are no more rows or if an error occurred. That "undef" can't be distinguished from an "undef" returned because the first field value was NULL. For these reasons you should exercise some caution if you use "selectrow_array" in a scalar context, or just don't do that.

The meme for spewing errors with a postfix or die uses "or" for a reason. It binds lower than all other operations, so it will be executed only if the entire statement itself fails (well, almost).

You have this error in the line above as well. I would also change your connect call to use the or meme instead of the || one.

As a learning device for others: this is a reason to include a complete working example of the failing code. Many (if not most) of the responses above were focusing on DBI/DBD, when in reality the problem was internal to perl operator misuse. That was not discovered until a complete code example was posted that exhibited the behavior.

and just so this gets picked up as an example when searching:

  • or vs ||

--MidLifeXis


In reply to Re^4: selectrow_array() confusion (or vs ||) by MidLifeXis
in thread selectrow_array() confusion by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found