Skip to content

Instantly share code, notes, and snippets.

@colinvh
Created March 28, 2019 17:28
Show Gist options
  • Save colinvh/485aff5eb3fff7c290e6fda1b2809178 to your computer and use it in GitHub Desktop.
Save colinvh/485aff5eb3fff7c290e6fda1b2809178 to your computer and use it in GitHub Desktop.
Delete multiple rows by ID with one statement (mysqli)
$ids = [1, 2, 3];
$qqq = join(', ', array_fill(0, sizeof($ids), '?'));
$iii = str_repeat('i', sizeof($ids));
$stmt = $conn->prepare("DELETE FROM table WHERE id IN ($qqq)");
$args = $ids;
array_unshift($args, $iii);
call_user_func_array([$stmt, 'bind_param'], $args);
$stmt->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment