masterlayouts Posted February 12, 2012 Share Posted February 12, 2012 The custom error handler function as defined in your book: function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) { $message = "An error occured in script '$e_file' on line $e_line: $e_message\n<br />"; $message .= "Date/Time: " . date('d-j-Y H:i:s') . "\n<br />"; $message .= "<pre>" . print_r($e_vars, 1) . "</pre>\n</p>"; if (!LIVE) { echo $message; } else { @mail(ADMINEMAIL, 'Site Error', $message); if($e_number != E_NOTICE) { echo "<div id=\"error\">A system error occurred.</div>"; } } } set_error_handler('my_error_handler'); It may handle errors as they happen in something like this one: $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " .mysqli_error($dbc)); My question is: How about the prepared statments? Can be something like: mysqli_stmt_execute($stmt) or trigger_error("Query: $q\n<br />MySQL Error: " .mysqli_error($dbc)); or should we use mysqli_stmt_error($stmt) and mysqli_stmt_errno($stmt)? Or maybe it is not necessary to do anything? Bottom line: how do we handle errors when using prepared statements? Thank you. 1 Link to comment Share on other sites More sharing options...
Larry Posted February 14, 2012 Share Posted February 14, 2012 The short answer is that you can use mysqli_error(), but I'll write something more formal up and share that with you in a couple of days. Link to comment Share on other sites More sharing options...
masterlayouts Posted February 24, 2012 Author Share Posted February 24, 2012 mysqli_stmt_execute($stmt) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_stmt_errno($stmt) . ": " . mysqli_stmt_error($stmt)); This seems to work fime. Do I have to modify something else in your function? Link to comment Share on other sites More sharing options...
Larry Posted February 25, 2012 Share Posted February 25, 2012 No, that looks fine, although the $q variable may not be too useful here. Link to comment Share on other sites More sharing options...
Recommended Posts