if语句选择在线数据库,如果可用,则选择本地数据库

if statement to select online db if available else select local db

In a project a internet is available the program use a server database. if internet is not available it will store on the local database.

if($_SERVER['HTTP_HOST'] === 'localhost'){

$_SESSION['vURL'] = 'http://localhost/example/';

}else{

    $_SESSION['vURL'] = 'http://www.example.com/';

    }

this defines a variable called vURL which can be used when linking to other pages. E.G

<a href="<?php echo vURL; ?>about.php">About Us</a>

connection_aborted: Check whether client disconnected

Returns 1 if client disconnected, 0 otherwise.

For More Info, Check connection-aborted - PHP Manual

if(connection_aborted() == 0)
{
    //Select Online DB
}
else
{
    //Select Local DB
}