I have the following scenario:
I have a script that conencts to a remote database, and all works good unless the remote database is offline or the server is offline.
If database/server goes offline, the script uses long time to execute, what would be the best way to check if db connection was successfull before executing the SQL?
class remote_db{
public $db;
public function __construct(){
$this->db = new mysqli("127.0.0.1","usr","pw","database");
$this->db->set_charset("utf8");
}
}
$remote_db = new remote_db();
if($remote_db){ echo 'hello world';}