【发布时间】:2022-09-30 23:12:11
【问题描述】:
为什么以下不起作用? 我想检查表中是否存在数组值。
$arr=range(1,1111);
// Attempt select query execution
$sql = \'SELECT * FROM tbl_numbers_stock WHERE lot_stock IN \' . implode( \',\', $arr ) . \' );\';
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
echo \"match found\";
}
// Close result set
mysqli_free_result($result);
} else{
echo \"No records matching your query were found.\";
}
} else{
echo \"ERROR: Could not able to execute $sql. \" . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
但它给出了错误
ERROR: Could not able to execute SELECT * FROM tbl_numbers_stock WHERE lot_stock IN 1,2,3,4,5,6,7,......1110,1111 );. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29...\' at line 1
-
在
IN之后必须是(