When you’re building a application with php and a MySQL database you can run into trouble when you don’t have a nice error handler. This article describes the minimum of a error handler.
The principles
- Run the query with php
- See if there is an error with the query
- Display the error while the rest of the script don’t dies!
The php
$sql = "SELECT name FROM table WHERE id = 1";
$res = mysql_query($sql);
//an error occures
if(!$res){
trigger_error(mysql_error($sql.'<br />'.$res));
}else{
//fetch the output
while($row = mysql_fetch_assoc($res)){
echo $row['name'].PHP_EOL;
}
}




