Hi there everyone, long time, no type!
I'm trying to help someone regarding an issue with a script. The problem I'm having is that the script will just blindly continue executing regardless of the fact that it's doing queries on tables and rows that don't exist. I'm trying to find out where the problems arise so I'd like to print these errors to screen but I've never worked with statements created like this(I think they're called prepared statements). Could someone tell me how I would modify this function to report the sql error to screen and kill the script?
// Insert into Database
function dbquery($sql, $returnresult = true)
{
$conn = new mysqli($GLOBALS['mysql_host'], $GLOBALS['mysql_user'], $GLOBALS['mysql_pass'], $GLOBALS['mysql_db']);
if ($conn->connect_errno) {
error_log('MySQL could not connect: ' . $conn->connect_error);
return $conn->connect_error;
}
$return = array();
$result = mysqli_query($conn, $sql);
if ($returnresult) {
if (mysqli_num_rows($result) != 0) {
while ($r = $result->fetch_assoc()) {
array_push($return, $r);
}
} else {
$return = array();
}
} else {
$return = array();
}
return $return;
}
Any help would be greatly appreciated. Thanks for your time!