PHP 单列模式实例讲解以及参考网址
1,http://blog.csdn.net/jungsagacity/article/details/7618587
2,http://www.cnblogs.com/lh460795/archive/2013/07/30/3225650.html
实例应用
Myclass.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?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
1 2 3 4 5 6 7 8 9 10 | <?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; ?> |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步