ted.byers:

Your SQL statements aren't actually formed properly, because you're using double-quoting and there's an unescaped '%' inside the text. So your SQL probably turned out to be something like:

select ... where ... OR mdf_20 LIKE '_a4bbf326102e3064a8d9e06558c4b5e2020ee353HASH(0x826998 +)' ^^^^^^^^^^^^^ +^

Your prepared statements have a different problem: you don't need to have quote characters in your arguments. It's likely turning into something like:

select ... where ... OR mdf_20 LIKE '''_a4bbf326102e3064a8d9e06558c4b5e2020ee353HASH(0x8269 +98)''' ^^ ^^^^^^^^^^^ +^^^^^

So first, be sure that you don't use the @ or % character inside double-quotes without escaping them. Second, go ahead and work with the parameterized version of the code, as it'll be better in the long term, and will be no more trouble to get running than the hardcoded version. I tweaked your second listing to be:

$sql = "SELECT action_id FROM transactions LEFT JOIN actions ON transactions.transaction_id = actions.transaction_id LEFT JOIN merchants ON merchant_id = idmerchants WHERE mdf_20 = ? AND action_type IN ('capture','sale') AND ABS(amount) = ABS(?) AND success = 1 AND processor_settlement_date IS NULL ORDER BY transaction_date;"; my $sth = $dbh->prepare($sql); $sth->bind_param(1, '1442a29888840b0b9505d34da6cd8897d153976d'); $sth->bind_param(2, 49.95); $sth->execute; my $aref = $sth->fetchrow_array if (defined $aref); print join(', ', @$aref),"\n"; $sth->bind_param(1, 'a4bbf326102e3064a8d9e06558c4b5e2020ee353'); $sth->bind_param(2, 4.95); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $sth->finish; my $like_cond = ''; $sql = "SELECT action_id,transaction_date FROM profitorius.actions WHERE transaction_id LIKE ? AND ABS(amount) = ABS(?) AND success = 1 AND action_type IN ('capture','sale') AND processor_settlement_date IS NULL ORDER BY transaction_date;"; $sth = $dbh->prepare($sql); $like_cond = '1442a29888840b0b9505d34da6cd8897d153976d%'; $sth->bind_param(1,$like_cond); $sth->bind_param(2, 49.95); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n"; $like_cond = 'a4bbf326102e3064a8d9e06558c4b5e2020ee353%'; $sth->bind_param(1,$like_cond); $sth->bind_param(2, 4.95); $sth->execute; $aref = $sth->fetchrow_array; print join(', ', @$aref),"\n";

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: SQL statement produces no results when executed using DBI's prepared statement, but one record when executed directly in MySQL. WHY? by roboticus
in thread SQL statement produces no results when executed using DBI's prepared statement, but one record when executed directly in MySQL. WHY? by ted.byers

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.