Let's say I have a user table ( id | nome
) and that where they are listed (client-side ) I can select multiple of them and delete them at the same time. >
How could I do this on a MySQL database using PDO?
I know that MySQL allows the use of the IN
clause that would serve for this type of query. Ex:
DELETE FROM usuarios WHERE id IN (37,45,58) # deletaria os ids 37, 45 e 58
The problem is that since ids
would be dynamic and the PDO uses prepared-statements , I do not know how I would proceed with the code in it. I imagine it would look something like:
$query = $pdo->prepare("DELETE FROM usuarios WHERE id IN :ids");
$query->bindParam(':ids', [37,45,58]); #array de ids vindo de um $_POST, por exemplo.
$query->execute();
Would there be any way to do something like the above code with dynamic values?