我希望检查表中数组存储值的出现.像这样的数组:
$myarray=array("122","123","124","125");
我不想在查询中内爆数组,因为它不安全.
SELECT ledger FROM mytable WHERE ledger IN('".implode("','",$myarray)."')
我想去准备好安全声明.我试图在for循环中运行查询,但它失败了.
$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; } }
这会抛出"对非对象调用成员函数bind_param()"错误.我相信有更好的方法可以做到这一点.有什么建议?