if (!$result = $mysqli->query($sql)) {
    // Print debug info if debug is enabled
    if ($debug) {
        echo "Error: Query execution failed because: \n";
        echo 'Query: '.$sql."\n";