3v4l.org

run code in 300+ PHP versions simultaneously
<?php $metas = array( 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' ); $limit = 10; $config = (object)array('recording_table' => 'recording', 'meta_table' => 'meta'); $join = array(); $params = array(); $types = ''; foreach ($metas as $key => $value) { $join[] = 'm.meta_key=? AND m.meta_value=?'; $params[] = $key; $params[] = $value; $types .= 'ss'; } // add the parameter for the `HAVING` check $params[] = count($metas); $types .= 'i'; // add the limit $params[] = $limit; $types .= 'i'; // make the query string $sql = "SELECT recording_id FROM {$config->recording_table} r JOIN {$config->meta_table} m ON m.recording_id = r.id AND (" . implode(' OR ', $join) . ") GROUP BY r.id HAVING COUNT(*) = ? LIMIT ?"; echo $sql . "\n"; print_r($params); print_r($types);

preferences:
41.32 ms | 405 KiB | 5 Q