0

Here is my prepared statement

 $stmt = $db->prepare("UPDATE user SET :property=:value WHERE `id`=:id");
 $stmt->execute([':property' => $property, ':value' => $value]);
 $row = $stmt->fetchAll(PDO::FETCH_ASSOC);

How can I quickly verify that the query has gone through successfully?

I was thinking maybe an if() around the execute part?

Heraclitus
  • 80
  • 11

2 Answers2

1

Try this

if($stmt->rowCount() > 0){
   echo 'SUCCESS';
}else{
   echo 'ERROR';
}
Abdalla Arbab
  • 1,360
  • 3
  • 23
  • 29
0

All you need to do is test the returned $stmt like this.

Remember both the prepare and the execute can fail and should be checked

$stmt = $db->prepare("UPDATE user SET :property=:value WHERE `id`=:id");
if ( $stmt == false ) {
    print_r($db->errorInfo());
    exit;
}
$stmt->execute([':property' => $property, ':value' => $value]);
if ( $stmt == false ) {
    print_r($db->errorInfo());
    exit;
}

This query will definitely fail

Now I look closer, you have a huge syntax error in the query. You cannot parameterise column or table names.

You also pave 3 parameters and only 2 values

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149