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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -