PHP automatically choose to connect local or remote database _php tips

Source: Internet
Author: User
Mysql.class.php file See http://www.jb51.net/article/25496.htm

Copy Code code as follows:

<?php
Include MySQL operations 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 ';
Successful local connection instantiate local MySQL class, otherwise connect remote database and instantiate 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 table names under the current database
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.