我有一个 id 数组$friends = array(0001, 0002, 0003, 0004)
和一个数据库,其中table_name = friends
, column_header = fid
. fid
infriends
可能包含也可能不包含其中一个朋友 ID。我想输入$friends
查询,并返回$friends
在fid
.
我确定这fid={array_values($friends)}
是错误的,但我不知道如何将 WHERE 部分传递给值数组...
//All DB_X's are defined in another file that is included in this actual file
$db = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME, DB_USER, DB_PASS);
$stmt = $db->prepare("SELECT fid FROM friends WHERE fid={array_values($friends)} ORDER BY fid ASC");
$stmt->execute();
$friendResults = $stmt->fetchAll();