ID 배열이 $friends = array(0001, 0002, 0003, 0004)
이고 데이터베이스가 table_name = friends
, column_header = fid
인 데이터베이스가 있습니다. 에 friends
은 친구 ID 중 하나를 포함 할 수도 있고 포함하지 않을 수도 있습니다. 쿼리에 $friends
을 입력하고 $friends
및 fid
에있는 현재 값을 모두 반환합니다.PDO를 사용하여 SQL 데이터베이스에서 배열 값 일치 (PHP)
나는 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();