开发者

PHP Array in MySQL IN() function?

开发者 https://www.devze.com 2022-12-22 00:53 出处:网络
Is it possible to assign php array in MySQL IN() function? for example, $numbers = array(\'8001254656\',\'8886953265\',\'88864357445\',\'80021536245\');

Is it possible to assign php array in MySQL IN() function? for example,

$numbers = array('8001254656','8886953265','88864357445','80021536245');
$sql = mysql_query("SELECT * FROM `number_table` WHERE `number` IN ($numbers)");

Any Ideas开发者_开发问答?

Thanks,


This code snippet should help you out, as long as number is restricted to numbers.

<?php

// Generate a filtered comma-separated list of the numeric values in numbers.
// Non-numeric values might allow for SQL-injection bugs.
$SQL_numberList = implode(", ", array_filter($numbers, 'is_numeric'));
$sql = mysql_query("SELECT * FROM `number_table` WHERE `number` IN ($SQL_numberList)");

For string arguments in the list you'll need to do something a little different.


No. Use implode() first.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号