简体   繁体   中英

Delete an array not working with PDO SQL?

it's been 3 hours that i'm trying to delete a row in mysql based on a id ... Seems simple right ?

Taking into consideration that the array might contains several value: $result = Array ( [3] => 4_Couture )

Array ( [3] => 4_Couture )
$sql_delete = "DELETE FROM users_resumes WHERE id_training_key = ? ";
$stmt_delete= $pdo->prepare($sql_delete);
foreach($result as $r) {
            $stmt_delete->execute($r);
    }

This seems to be right no ? error : PDOStatement::execute() expects parameter 1 to be array, string given

Any, any, any clue is very welcome ! thanks a lot from France !

Assuming $result is a one-dimensional array like

$result = [ 3 => '4_Couture' ];

That means you're trying to call $stmt->execute() with a single string value where it requires an array.

I suggest you use bindParam instead

$stmt_delete = $pdo->prepare("DELETE FROM users_resumes WHERE id_training_key = ?");
$stmt_delete->bindParam(1, $r);
foreach ($result as $r) {
  $stmt_delete->execute();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM