The right way to check whether mysqli query was successful

Viewed 4955

I've read several articles about the problem like this however none of them helped me and I am a bit confused what to do.

Basically, I want to check whether the sql query performed without any errors. To do that, do I have to use both of the if statements shown below?

if($stmt = $mysqli->prepare("INSERT INTO table VALUES (?, ?, ?);"))
{
    $stmt->bind_param("sss", $a, $b, $c);

    if(!$stmt->execute())
    {
        // Do I have to catch the problem here?
    }

    if($stmt->affected_rows === -1){
       // Do I have to catch the problem here?
    }

    $stmt->close();
}
else
{
    // Do I need to catch the problem here?
}
2 Answers
Related