1,http://blog.csdn.net/jungsagacity/article/details/7618587
2,http://www.cnblogs.com/lh460795/archive/2013/07/30/3225650.html
实例应用
Myclass.php
<?php header("Content-type: text/html; charset=utf-8"); header('Access-Control-Allow-Origin:*'); $BiaDuak = '2q5OVS3LlFuZcoXGtXvqxAYq';//定义一般变量 define("accessKeyId","8LdVru54GybHc2DB"); //定义常量 class DbHelp { public $servername="5657d48145af1.sh.cdb.myqcloud.com:4065"; public $username="mydata" ; public $password="w12345"; public $dbname="allhelp"; private static $_instance; public static function getInstance() { if(! (self::$_instance instanceof self) ) { self::$_instance = new self(); } return self::$_instance; } private function __construct(){} private function __clone(){} } ?>
other.php
<?php header("Content-type: text/html; charset=utf-8"); header('Content-Type: application/json'); header('Access-Control-Allow-Origin:*'); require "Myclass.php"; $dbcontext=DbHelp::getInstance(); echo $BiaDuak; echo accessKeyId; echo $dbcontext->servername; ?>