<?php
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
$BiaDuak = '************';//定义变量 使用时 echo $BiaDuak;
define("accessKeyId","************");//定义常量 使用时 echo accessKeyId;
define("accessKeySecret","************");
define("endpoint","************");
//公共类
class DbHelp
{
private $servername="************.com:4065";
private $username="root" ;
private $password="w386161506";
private $dbname="allhelp_db";
public $conn;
private static $_instance;
public static function getInstance()
{
if(! (self::$_instance instanceof self) )
{
self::$_instance = new self(); }
return self::$_instance;
}
private function __construct(){ $this->conn=new mysqli($this->servername,$this->username,$this->password,$this->dbname);
}
private function __clone(){}
}
//公共函数
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr();// "-"
$uuid =
substr($charid, , )
.substr($charid, , )
.substr($charid,, )
.substr($charid,, )
;
return $uuid;
}
function guid(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr();// "-"
$uuid = chr()// "{"
.substr($charid, , ).$hyphen
.substr($charid, , ).$hyphen
.substr($charid,, ).$hyphen
.substr($charid,, ).$hyphen
.substr($charid,,)
.chr();// "}"
return $uuid;
}
}
function createguid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr();// "-"
$uuid =
substr($charid, , ).$hyphen
.substr($charid, , ).$hyphen
.substr($charid,, ).$hyphen
.substr($charid,, ).$hyphen
.substr($charid,,)
;
return $uuid;
}
//用于继承的基类
class DbHelpBase
{
public $servername;
public $username;
public $password;
public $dbname;
public $conn;
public function DbHelpBase(){
$this->servername="************:4065";
$this->username="root" ;
$this->password="w386161506";
$this->dbname="allhelp_db";
$this->conn=new mysqli($this->servername,$this->username,$this->password,$this->dbname);
}
public function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
public function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr();// "-"
$uuid =
substr($charid, , )
.substr($charid, , )
.substr($charid,, )
.substr($charid,, )
;
return $uuid;
}
}
//用于组合的类
class DbHelpField
{
public $servername;
public $username;
public $password;
public $dbname;
public $conn;
private static $_instance;
public static function getInstance()
{
if(! (self::$_instance instanceof self) )
{
self::$_instance = new self(); }
return self::$_instance;
}
private function __construct(){
$this->servername="************:4065";
$this->username="root" ;
$this->password="w386161506";
$this->dbname="allhelp_db";
$this->conn=new mysqli($this->servername,$this->username,$this->password,$this->dbname);
}
private function __clone(){}
public function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
public function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr();// "-"
$uuid =
substr($charid, , )
.substr($charid, , )
.substr($charid,, )
.substr($charid,, )
;
return $uuid;
}
}
?>
<?php
header("Content-type: text/html; charset=utf-8");
header('Content-Type: application/json');
header('Access-Control-Allow-Origin:*');
require "config.php";
class DataUser
{
private $conn;
public function DataUser()
{
$dbcontext=DbHelp::getInstance();
$this->conn=$dbcontext->conn;
if($this->conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
} }
public function Query_alluser()
{
$sql = "SELECT * FROM users";
$result = $this->conn->query($sql);
$data =array();
if ($result->num_rows > )
{
while($rowObject = $result->fetch_object())
{
$data[]=$rowObject;
}
$json = json_encode($data);//把数据转换为JSON数据.
echo "{".'"Comment"'.":".$json."}";
}
else
{
echo "0 results";
}
}
}
echo "直接使用config.php中的类";
$t=new DataUser();
$t->Query_alluser();
echo "\n"; class DataUser1 extends DbHelpBase
{
public function Query_alluser()
{
$sql = "SELECT * FROM users";
$result = $this->conn->query($sql);
$data =array();
if ($result->num_rows > )
{
while($rowObject = $result->fetch_object())
{
$data[]=$rowObject;
}
$json = json_encode($data);//把数据转换为JSON数据.
echo "{".'"Comment"'.":".$json."}";
}
else
{
echo "0 results";
}
}
}
echo "继承config.php中的类";
$tt=new DataUser1();
echo $tt->servername;
echo $tt->create_guid();
echo $tt->Query_alluser();
echo "\n";
class DataUser2
{
public $conn;
public $formDbHelp;
public function DataUser2()
{
$formDbHelp=DbHelpField::getInstance();
$this->conn= $formDbHelp->conn;
}
public function Query_alluser()
{
$sql = "SELECT * FROM users";
//$result = $this->formDbHelp->conn->query($sql);//PHP中好像不能三级访问古多定义一个$conn字段
$result = $this->conn->query($sql);
$data =array();
if ($result->num_rows > )
{
while($rowObject = $result->fetch_object())
{
$data[]=$rowObject;
}
$json = json_encode($data);//把数据转换为JSON数据.
echo "{".'"Comment"'.":".$json."}";
}
else
{
echo "0 results";
}
}
public function CreateGuid()
{
echo $this->formDbHelp->create_guid();//错误
}
}
echo "组合config.php中的类";
$ttt=new DataUser2();
echo $ttt->Query_alluser();
//echo $ttt->formDbHelp->create_guid();//错误
?>

PHP 继承,组合,单模式,GUID,等混合实例的更多相关文章

  1. Unity 游戏框架搭建 (十三) 无需继承的单例的模板

    之前的文章中介绍的Unity 游戏框架搭建 (二) 单例的模板和Unity 游戏框架搭建 (三) MonoBehaviour单例的模板有一些问题. 存在的问题: 只要继承了单例的模板就无法再继承其他的 ...

  2. Learn day7 继承(单、多、菱形)\多态\魔术方法\装饰器\异常

    1.继承 1.1 单继承# ### 继承 """ (1) 单继承 (2) 多继承 至少2个类,子类和父类 一个类继承另外一个类,当前类是子类 (衍生类) 被继承的这个类是 ...

  3. 不可或缺 Windows Native (21) - C++: 继承, 组合, 派生类的构造函数和析构函数, 基类与派生类的转换, 子对象的实例化, 基类成员的隐藏(派生类成员覆盖基类成员)

    [源码下载] 不可或缺 Windows Native (21) - C++: 继承, 组合, 派生类的构造函数和析构函数, 基类与派生类的转换, 子对象的实例化, 基类成员的隐藏(派生类成员覆盖基类成 ...

  4. Java 实现组合(Composite)模式

    类图 /** * 树 总体 * * @author stone * */ public class Tree { private TreeNode root; //根节点 public Tree(St ...

  5. 05_Elasticsearch 单模式下API的增删改查操作

    05_Elasticsearch 单模式下API的增删改查操作 安装marvel 插件: zjtest7-redis:/usr/local/elasticsearch-2.3.4# bin/plugi ...

  6. Elasticsearch 单模式下API的增删改查操作

    <pre name="code" class="html">Elasticsearch 单模式下API的增删改查操作 http://192.168. ...

  7. C++中的类继承之单继承&多继承&菱形继承

     C++中的类继承之单继承&多继承&菱形继承 单继承是一般的单一继承,一个子类只 有一个直接父类时称这个继承关系为单继承.这种关系比较简单是一对一的关系: 多继承是指 一个子类有两个或 ...

  8. JavaScript-原型&原型链&原型继承&组合函数

    小小的芝麻之旅: 今天学习了js的原型,要说原型,我们先简单说一下函数创建过程. 原型 每个函数在创建的时候js都自动添加了prototype属性,这就是函数的原型,原型就是函数的一个属性,类似一个指 ...

  9. Python开发基础-Day19继承组合应用、对象序列化和反序列化,选课系统综合示例

    继承+组合应用示例 class Date: #定义时间类,包含姓名.年.月.日,用于返回生日 def __init__(self,name,year,mon,day): self.name = nam ...

随机推荐

  1. poj 3230 Travel(dp)

    Description One traveler travels among cities. He has to pay for this while he can get some incomes. ...

  2. Appium for Windows环境搭建

    服务环境: 1.安装Nodejs 下载nodejs安装包(http://nodejs.org/download/)安装 测试安装是否成功:运行cmd,输入node -v 2.安装android的SKD ...

  3. 从linux telnet到exchange邮件server来測试发送邮件

    我们在Linux下,能够通过telnet邮件server的25port(一般smtp邮件server都是这个),来測试是否能发送邮件. 前提是先得把DNS配好,或者/etc/hosts文件制定好邮件s ...

  4. -bash: ulimit: max user processes: cannot modify limit: Operation not permitted

    安装oracle时候在创建oracle用户后,切换oracle用户时,报如下错 [root@localhost ~]# su - oracle-bash: ulimit: max user proce ...

  5. 基本文件的I/O

    System.IO命名空间包含允许在数据流和文件上进行同步,异步及写入的类型.文件是一些永久存储及具有特定顺序的字节组成的一个有序的,具有名称的集合.与文件有关的概念是目录路径和磁盘存储等.流提供了一 ...

  6. 常见Web Service 使用网址

    下面的网址是常用Web Service http://www.webxml.com.cn/zh_cn/web_services.aspx 里面的很多Web Service接口...可以用到的,很有用!

  7. think in python 11 字典

    字典 字典类似于列表,但更加通用 键值对 ,字典是 键与值之间的映射,每个键都映射到一个值上 dict可以创建一个不包含任何项的字典 eng2sp = dict() print eng2sp 还可以给 ...

  8. js 刷新网页

    1. Javascript 返回上一页history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forw ...

  9. C#高效分页代码(不用存储过程)

    首先创建一张表(要求ID自动编号): create table redheadedfile ( id ,), filenames ), senduser ), primary key(id) ) 然后 ...

  10. HDU 1017 - A Mathematical Curiosity

    题目简单,格式酸爽.. #include <iostream> using namespace std; int ans,n,m,p; int main() { cin>>p; ...