php - Can I use an exception with a database query? -
is possible use exception @ end of mysql query instead of die()? i'd throw exception , log instead of killing script.
would done like:
mysql_query(...) or throw new exception()??
this way it. have database in wrapper class, $this
refers wrapper.
private function throwexception($query = null) { $msg = mysql_error().". query was:\n\n".$query. "\n\nerror number: ".mysql_errno(); throw new exception($msg); } public function query($query_string) { $this->queryid = mysql_query($query_string); if (! $this->queryid) { $this->throwexception($query_string); } return $this->queryid; }
that packages nice error message me, can see problem query. keep simpler of course, , do:
mysql_query($sql) or throw new exception("problem query: ".$sql);
Comments
Post a Comment