开发者

PHP Array in MySQL IN() function?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜