0

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 !

2
  • What exactly is $result? Where do you assign a value? $result = Array ( [3] => 4_Couture ) is not valid PHP code Commented Aug 26, 2020 at 1:38
  • Alternative approach to current answer $stmt_delete->execute(array($r)); or use ternary and is_array. Commented Aug 26, 2020 at 2:29

1 Answer 1

4

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

Dude, you've juste make it work ! Indeed the array wasn't multidimensional ! This is why my code wasn't corking ! I've learned a huge one tonight thanks to you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.