I've been messing around with the MySQLi
object in PHP
, and was getting used to preparing statements before executing them.
Thus far I've mostly been doing the following :
if($stmt = $mysqli->prepare($sql) == false){
return $mysqli->error;
}
Which, when it failed, has always told me that my SQL was wrong basically.
Assume the following :
- A check has been done to ensure
MySQL
connectivity - The
SQL
is correct, even if it returns 0 rows. - All relevant tables exist.
Under what circumstances could a prepared statement fail? I ask, mainly wondering if there is any point to if($stmt = $mysqli->prepare($sql))
, or am I just wasting lines of code?