12
Let’s say I have a user table (id | nome
) and that where they are listed (client-side) i can select several of them and delete them at the same time.
How could I do this in a Mysql database using PDO?
I know that Mysql allows the use of the clause IN
which would serve 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 like the ids
would be dynamic and PDO uses Prepared-statements, I don’t know how I would do with the code on it. I imagine it would be 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 have some way to do something like the code above, with dynamic values?
It worked perfectly! Thank you.
– Kazzkiq
@Zuul Thanks for the edition
– Maicon Carraro