<?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. IOC原理分析

    IOC(inversion of control)控制反转 在我们的程序中,要实现某个功能,我们都会用到两个或两个以上的类来协同完成,那么在一个类中,我们就会要有它的合作类的引用,也就是说这个类依赖于 ...

  2. golang基础数据结构

    一.概述: 这里主要讨论四种类型---数组.slice.map和结构体 数组和结构体是聚合类型:它们的值都是由很多个元素或者成员字段的值组成.数组是有同构元素组成--每个数组的元素的类型相同:结构体为 ...

  3. RSA不对称加密,公钥加密私钥解密,私钥加密公钥解密

    RSA算法是第一个能同时用于加密和数字签名的算法,也易于理解和操作. RSA是被研究得最广泛的公钥算法,从提出到现在已近二十年,经历了各种攻击的考验,逐渐为人们接受,普遍认为是目前最优秀的公钥方案之一 ...

  4. < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />

    目录(?)[-] 1 meta http-equiv  X-UA-Compatible content  chrome1 1 meta http-equiv  X-UA-Compatible cont ...

  5. vbox下安装 linux 64 bit出现“kernel requires an x86_64 cpu

        今天在vbox下安装linux 64bit出现"kernel requires an x86_64 cpu, but only detected "的错误,网上有很多文章介 ...

  6. Java生成PDF报表

    一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iText--用于生成PDF文档的一个Java类库.废话不多说,进入正题. 二.iText简介 iText是著名的开放 ...

  7. iOS开发那些事儿(三)JsonKit解析原理

    json_parse_it :开始解析,字符串指针从头到尾循环 jk_parse_next_token:获取下个字符的type和length 大部分分隔符长度都是固定1 jk_parse_string ...

  8. C#.net 摄像头驱动程序,用avicap32.dll

    装了摄像头后一般会有 avicap32.dll文件,没有一样可以用这些代码. 不需要在解决方案里面引用这个.dll文件. 下面有二种写法的例子: 例一: using System;using Syst ...

  9. 简洁的jsp

    在开发 是使用tomcat7版本(7的jslt表达式语法检查更加严格) 1.去除生产html的不必要的空行 <%@ page trimDirectiveWhitespaces="tru ...

  10. Android混淆、反编译以及反破解的简单回顾

    =========================================================================虽然反编译很简单,也没下面说的那么复杂,不过还是转了过 ...