<?php //单例模式:一个类仅允许被实例化一次 /** * */ //仅允许被实例化一次 $db = array( 'host'=>'localhost',//地址 'user'=>'root',//数据库用户名 'password'=>'root',//数据库密码 'database'=>'ceshi',//数据库名 ) class db { public $conn; public static $sql; public static $instance=null; private function __construct(){ require_once('database.php'); $this->conn = mysqli_connect($db['host'],$db['user'],$db['password']); if(!mysqli_select_db($this->conn,$db['database'])){ echo "失败"; }; mysqli_query($this->conn,'set names utf8'); } } ?>