Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO prepared statement in UPDATE Multiple ID

I am Developing a simple shopping system and using PDO. But I can't seem to use PDO while updating using multiple values ... Look here :

    // GET MESSAGES ID AND REPLACE '-' WITH ','
    $mid = explode("," , str_replace( '-' , ',' , $mid ));
    $isread = "read";

    $stmt = $conn->prepare("UPDATE `mshop_pms` SET `readperm` = ? WHERE `mid` IN (?)");
    $stmt->execute(array($isread, array($mid)));

How can I do this? and do this :

$stmt->execute(array($isread, $mid));

Without explode It just Update first row.

like image 316
SayJeyHi Avatar asked Apr 24 '26 22:04

SayJeyHi


1 Answers

It won't work in this way. You need to iterate over the exploded array, then keep on updating.

Here's an example:

// GET MESSAGES ID AND REPLACE '-' WITH ','
$mid = explode(",", str_replace('-', ',', $mid));
$isread = "read";
$stmt = $conn->prepare("UPDATE `mshop_pms` SET `readperm` = :readperm WHERE `mid` = :mid");
//now update and iterate
foreach ($mid as $m) {
    $s->bindParam(':readperm', $isread);
    $s->bindParam(':mid', $m);
    $s->execute();
}
like image 192
Akshay Avatar answered Apr 27 '26 11:04

Akshay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!