PHP自動選擇 串連本地還是遠端資料庫

來源:互聯網
上載者:User

Mysql.class.php 檔案見 http://www.jb51.net/article/25496.htm

複製代碼 代碼如下:<?php
// 包含Mysql操作類
include_once 'Mysql.class.php';
// 本地mysql資料
$mysql_local_data = array('db_host'=>'localhost',
'db_user'=>'root',
'db_pass'=>'root',
'db_name'=>'test');
// 遠程mysql資料
$mysql_remote_data = array('db_host'=>'61.183.41.178',
'db_user'=>'XXX',
'db_pass'=>'XXX',
'db_name'=>'XXX');
// 公用資料
$tb_prefix = 'php95_';
$db_charset = 'UTF-8';
//本地串連成功則執行個體化本地Mysql類,否則串連遠端資料庫並執行個體化Mysql類
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(); //測試:顯示當前資料庫下的所有表名
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.