我何时应该调用
mysqli :: close?我从来没有习惯使用if语句来检查bind_param(),prep()和execute()是否成功.我应该在方法的末尾(下面)调用$stmt-> close().或者我应该在每个条件之后调用它,确保我关闭数据库连接,即使进程在某个阶段失败,例如bind param.
public function function_name($id,$new_id ){ $query = "UPDATE TABLE SET name = ? WHERE field = ? "; if($stmt=$this->prepare($query)){ if($stmt->bind_param("is",$id,$new_id)){ if($stmt->execute()){ }else{//Could not execute the prepared statement $message = "Could not execute the prepared statement"; } }else{//Could not bind the parameters $message = "Could not bind the parameters"; } }else{ $message = "Could not prepare the statement"; } return $message }