PHP自动选择 连接本地还是远程数据库

yipeiwu_com6年前PHP代码库
Mysql.class.php 文件见 https://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(); //测试:显示当前数据库下的所有表名
?>

相关文章

解析smarty模板中类似for的功能实现

1. 功能说明,在页面使用smarty循环100次输出,类似for循环100次{section name=total loop=100}{$smarty.section.total.in...

php中static和const关键字用法分析

php中static和const关键字用法分析

本文实例讲述了php中static和const关键字用法。分享给大家供大家参考,具体如下: static关键字在类中描述的成员属性和成员函数都是静态的。 static成员能限制外部的访问...

ThinkPHP中RBAC类的四种用法分析

本文实例讲述了ThinkPHP中RBAC类的四种用法。分享给大家供大家参考。具体方法如下: 第一类:放在登陆控制器的登陆操作中 1.RBAC::authenticate(); 用于在用户...

学习php过程中的一些注意点的总结

1.php传值到javascript php传值给javascript的方式:需要在<?php ?>标签外面打上引号 document.getElementById("tit...

POSIX 风格和兼容 Perl 风格两种正则表达式主要函数的类比(preg_match, preg_replace, ereg, ereg_replace)

首先来看看 POSIX 风格正则表达式的两个主要函数: ereg 函数:(正则表达式匹配) 格式:int ereg ( string pattern, string string [,...