I want to check for the presence of stored array values ββin a table. An array like this:
$myarray=array("122","123","124","125");
I do not want to embed the array in the request because it is not safe.
SELECT ledger FROM mytable WHERE ledger IN('".implode("','",$myarray)."')
I want a prepared expression for security. I tried running queries in a for loop, but it fails.
$not = sizeof($myarray); for ($i = 0; $i < $not; $i++) { $qc = 'SELECT ledger FROM mytable WHERE ledger = ?'; $st = $mysqli->prepare($qc); $st->bind_param("i", $myarray[$i]); $st->execute(); $ro = $st->num_rows; if ($ro > 0){ echo "number exists"; break; } }
This calls "Calling the member function bind_param () on an error other than an object." I am sure there is a better way to do this. Any suggestions?
source share