Folks
When an error occurs on prepared statements , mysqli, mysql etc. I do not want the user seeing the technical error reports so trying to dump it to db. And show the user a user friendly mssg.
Is this how I should do it:
[code]
ini_set(“display_errors”,1);
ini_set(“display_startup_errors”,1);
error_reporting(E_ALL);
if(!mysqli_stmt_prepare($stmt,$sql_count))
{
$_SESSION[‘error_report’] = __LINE__ .”n”;
$_SESSION[‘error_report’] = ‘Mysqli Error: ‘ .mysqli_error($conn) .”n”;
$_SESSION[‘error_report’] = ‘Mysqli Error Number: ‘ .mysqli_errno($conn) .”n”;
report_error($_SESSION[‘error_report’]);
die(‘Something went wrong. Please try again later!’);
}
function report_error($data=NULL)
{
$data = $_SESSION[‘error_report’];
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect(“localhost”,”root”,””,”buzz”); //mysqli_connect(“server”,”user”,”password”,”db”);
//$stmt = mysqli_prepare($conn,”INSERT into error_reports(mysqli_error,mysqli_errno) VALUES(?,?)”);
$stmt = mysqli_prepare($conn,”INSERT into error_reports(issue) VALUES (?)”);
//mysqli_stmt_bind_param($stmt,”ii”,$mysqli_error,$mysqli_errno);
mysqli_stmt_bind_param($stmt,”s”,$_SESSION[‘error_report’]);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
report_error($_SESSION[‘error_report’]);
Tbl Col ‘issue’is not VarChar but TEXT.
Q1. Is this ok ?
A.
[code]
function report_error($data=NULL)
Or should I change it to:
B.
[code]
function report_error($data)
Or should I just leave it empty, like so:
C.
[code]
function report_error()
I tried many times learning all that try, catchall stuff but it just does not sink in.
So, trying a very basic error recording to db.