PHP automatically selects whether to connect to a local or remote database
- 2020-03-31 21:25:50
- OfStack
Mysql. Class. PHP file (link: #)
<?php
//Contains the Mysql action class
include_once 'Mysql.class.php';
//Local mysql data
$mysql_local_data = array('db_host'=>'localhost',
'db_user'=>'root',
'db_pass'=>'root',
'db_name'=>'test');
//Remote mysql data
$mysql_remote_data = array('db_host'=>'61.183.41.178',
'db_user'=>'XXX',
'db_pass'=>'XXX',
'db_name'=>'XXX');
//Public data
$tb_prefix = 'php95_';
$db_charset = 'UTF-8';
//A successful local connection instantiates the local Mysql class, otherwise connect to the remote database and instantiate the Mysql class
if (@mysql_connect($mysql_local_data[db_host], $mysql_local_data[db_user], $mysql_local_data[db_pass]))
$db = new Mysql($db_host, $mysql_local_data[db_user], $mysql_local_data[db_pass], $mysql_local_data[db_name], $db_charset, $conn);
else
$db = new Mysql($mysql_remote_data[db_host], $mysql_remote_data[db_user], $mysql_remote_data[db_pass], $mysql_remote_data[db_name], $db_charset, $conn);
$db->show_tables(); //Test: displays all the table names under the current database
?>