ballhogjoni Posted July 18, 2008 Share Posted July 18, 2008 Whats the best way to report a mysql error to the browser without killing the rest of the script? Basically I want to put mysql_error() into a variable and print that variable to the browser but I don't want to do this: or die(mysql_error()) Link to comment https://forums.phpfreaks.com/topic/115441-solved-report-mysql-error-without-die/ Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Like? mysql_query("Query Here") or $error = mysql_error(); Link to comment https://forums.phpfreaks.com/topic/115441-solved-report-mysql-error-without-die/#findComment-593453 Share on other sites More sharing options...
ballhogjoni Posted July 18, 2008 Author Share Posted July 18, 2008 looks good. Link to comment https://forums.phpfreaks.com/topic/115441-solved-report-mysql-error-without-die/#findComment-593455 Share on other sites More sharing options...
craygo Posted July 18, 2008 Share Posted July 18, 2008 <?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 Link to comment https://forums.phpfreaks.com/topic/115441-solved-report-mysql-error-without-die/#findComment-593457 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 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>"; } Link to comment https://forums.phpfreaks.com/topic/115441-solved-report-mysql-error-without-die/#findComment-593460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.