Jump to content

[SOLVED] report mysql error without die()


ballhogjoni

Recommended Posts

<?php
$errors = '';
$res = @mysql_query($sql);
if(!$res){
$errors .=  "there is a problem with your query. Error: ".mysql_error();."<br>\n";
}
echo $errors;
?>

 

now you can gather all errors or even gather successful queries with an else.

 

<?php
$results = '';$res = @mysql_query($sql);
if(!$res){
$results .=  "there is a problem with your query. Error: ".mysql_error();."<br>\n";
} else {
$results .= "Query $sql was run successfully<br>\n";
}
echo $results;
?>

 

Ray

Yeah you could take it further and store it in arrays.

 

$errors = array();

$query1 = @mysql_query("query") or $errors[] = mysql_error();
$query2 = @mysql_query("query") or $errors[] = mysql_error();
$query3 = @mysql_query("query") or $errors[] = mysql_error();

if(!empty($errors)){
echo "We encountered some MySQL errors:<ol>";
foreach($errors as $err){
echo "<li>{$err}</li>";
}
echo "</ol>";
}

 

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.