What is the most efficient way to MySQLand PHPcheck if there is a list of all identifiers? I want the result of returning the function to truebe if all exists , otherwise false.
I thought:
$ids = array(2233, 5545, 9478, 5343, 3545);
do_all_groups_exist($ids);
function do_all_groups_exist(array $ids = array()) {
if(empty($ids)) {
return true;
}
$SQL = "SELECT count(`id`) as count
FROM groups
WHERE `id` IN (" . implode(',', $ids) . ")";
...
$row = mysqli_fetch_object($result);
return (intval($row->count) === count($ids)) ? true : false;
}
Is there a better way?
source
share