I wish to check for the occurrence of stored values of an array in a table. An array like this:
$myarray=array("122","123","124","125");
I don't want to implode the array in the query as it is not secure.
SELECT ledger FROM mytable WHERE ledger IN('".implode("','",$myarray)."')
I want to go for prepared statement for security. I tried to run the 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 throws "Call to a member function bind_param() on a non-object" error. I am sure there is a better way to do this. Any suggestions?