Is there any way to redirect if you can’t find the mysql database?

Asked

Viewed 31 times

-1

I’m having a question, is there any way to redirect the user to a page 404 in case you can’t find the database on the connection? follows my code

$banco = 'qfood_'.$bdv;
            $conn1 = mysqli_connect('localhost', 'root', '', "$banco");



    $database_conn1 = "$banco";
            //verifica a conexão
            if ($conn1->connect_error) {
                die("Falha ao realizar a conexão: " . $conn1->connect_error);
    } else{

                $conn1->set_charset("utf8");
            }
    ?>

1 answer

2


$banco = 'qfood_'.$bdv;
            $conn1 = mysqli_connect('localhost', 'root', '', "$banco");



    $database_conn1 = "$banco";
            //verifica a conexão
            if ($conn1->connect_error) {
                http_response_code(404);
                include('my_404.php'); //forneça seu próprio HTML para o erro
                die();
    } else{

                $conn1->set_charset("utf8");
            }
    ?>

Reference http_response_code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.