<?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. Hibernate问题之'hibernate.dialect' not set

    继前文:Hibernate4中buildSessionFactory方法废弃问题.后 继续有问题.本来之前好好的项目,用了这种新的方法后发现问题. 出现  Connection cannot be n ...

  3. php算法之快速排序

    /** * 快速排序 * 原理: * 快速排序使用分治法(Divide and conquer)策略来把一个串行(list)分为两个子串行(sub-lists). * 最差时间复杂度 O(n*n) * ...

  4. Parallels destop8 无法创建bootcamp虚拟机

    创建基于Boot Camp的虚拟机时弹出“PRL_ERR_DISK_FILE_OPEN_ERROR (0x80021014)”错误提示,由于Mac系统权限错误或Boot Camp内Windows系统权 ...

  5. 创建和使用RMAN存储脚本

    创建和使用RMAN存储脚本:1.连接恢复目录(可以不连接到目标库):C:\Users\Administrator>rman target sys/rusky@rusky catalog=rcat ...

  6. oc结构

    结构 在oc中只能声明变量 不能声明函数和类 结构声明 struct DateT { int month; int day; int year; }; 结构可以在起最后的分号之后定义结构变量,并且可以 ...

  7. 关于C#重写,隐藏的一些事

    第一次开始写技术博客,不知该从何处下手,本人算是菜鸟一枚,每每看到博客园里面的大牛们分享的技术文章,只能望其项背,高不可攀.但细细想来,若不尝试着从小处从低处慢慢去积累分享,想要成为技术大牛也只能沦为 ...

  8. c# 另存为excel

    去网上找了一下  看了一个比较简单的新建excel然后另存为. 要引用Microsoft.Office.Interop.Excel命名空间,如果没有的话 ,百度比我懂. 直接付代码: Microsof ...

  9. hdu1004Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  10. js删除数组里的某个元素

    首先可以给js的数组对象定义一个函数,用于查找指定的元素在数组中的位置,即索引,代码为: Array.prototype.indexOf = function(val) { for (var i = ...