Home > Backend Development > PHP Tutorial > PHP automatically chooses whether to connect to a local or remote database_PHP tutorial

PHP automatically chooses whether to connect to a local or remote database_PHP tutorial

WBOY
Release: 2016-07-21 15:33:27
Original
730 people have browsed it

The Mysql.class.php file can be found at http://www.jb51.net/article/25496.htm

Copy the code The code is as follows:

//Include Mysql operation 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';
// If the local connection is successful, instantiate 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: display all tables under the current database First name
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322612.htmlTechArticleMysql.class.php file is available at http://www.jb51.net/article/25496.htm Copy code The code is as follows: ?php // Include Mysql operation class include_once 'Mysql.class.php'; // Local mysql data $mysql_l...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template