PHP automatically chooses to connect to the local database or remote database _ PHP Tutorial

Source: Internet
Author: User
PHP automatically chooses to connect to the local database or remote database. For the mysql.class.php file, see www.jb51.netarticle25496.htm. The Copy code is as follows :? Php contains Mysql operation class include_onceMysql.class.php; local mysql data $ mysql_l Mysql. class. php file see http://www.jb51.net/article/25496.htm

The code is as follows:


// Contains the 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, the local Mysql class is instantiated. Otherwise, the local database is connected and the Mysql class is instantiated.
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], $ response [db_pass], $ mysql_remote_data [db_name], $ db_charset, $ conn );
$ Db-> show_tables (); // test: displays the names of all tables in the current database.
?>

Http://www.bkjia.com/PHPjc/322612.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322612.htmlTechArticleMysql.class.php file see the http://www.jb51.net/article/25496.htm code as follows :? Php // contains the Mysql operation class include_once 'MySQL. class. php'; // Local Mysql data $ mysql_l...

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.