So I usually do it. I have my database in a wrapper class, so it $thisjust references the 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;
}
For me, this is all with a good error message, so I see the problem. Of course, you could make it a lot easier and do:
mysql_query($sql) or throw new Exception("Problem with query: ".$sql);
source
share