0

I have a situation in some really old code of mine where I am trying to pass through the data from a string and do a DB query off of those values.

The data loads correctly if I set $hula = '7630' but when I set it to multiple values in a string like $hula = '7890, 5630' I get error (Message: db2_execute(): Statement Execute Failed)

I clearly know I am missing something here but I am CLEARLY not seeing it. Thanks

<?php
    $hula = '7890, 5630';
    $stmt = "SELECT TXLCT2, ZFDLDS FROM ".$ArEnviro>getDataLibFin().".TXPL6C2, ".
    $ArEnviro->getDataLibFin().".HXPTABLD WHERE TXLCT2 = CFDECD AND CFDTCD = 'YCT2' AND TXLLV6 IN ? ORDER BY TXLCT2";
    $preparedStmt = db_prepare($ArConnections->getDB2ConnResource(),$stmt);
    $result = db_execute($preparedStmt, [$hula]);
    while(($row = db_fetch_both($preparedStmt)) == true) {
    echo('<option value="'.htmlspecialchars($row["TXLCT2"]).'">'.htmlspecialchars($row["TXLCT2"]).' - '.htmlspecialchars($row["ZFDLDS"]).'</option>');
}
?>
Kusum
  • 501
  • 2
  • 11
  • 30
bldev
  • 137
  • 1
  • 1
  • 12
  • echo `$stmt ` and check what it returns!! – Saty Aug 04 '16 at 12:11
  • Look at how it would be when parameters are resolved: `....... AND TXLLV6 IN '7890, 5630'` - does that look valid to you? – Niet the Dark Absol Aug 04 '16 at 12:12
  • In MySQL (which is how you tagged this), the `?` at `IN ?` can't be in the way you're doing it. You need `IN (?, ?)` and to bind each one individually. Check http://stackoverflow.com/questions/6178926/php-prepared-statements-with-an-array – apokryfos Aug 04 '16 at 12:13
  • You are both correct, it doesnt look correct and I did check that other stack overflow quetion and that is the answer I was looking for. Thanks – bldev Aug 04 '16 at 12:17

1 Answers1

0

A simple change:

if TXLLV6 is integer:

$hula = '(7890, 5630)';

If it is varchar or any kind of string:

$hula = "('7890', '5630')";
Mojtaba
  • 4,852
  • 5
  • 21
  • 38