/*一个文件MySQLDB.class.php中包含了一个类来连接数据库、
执行语句的方法、
将查询到的结果集通过数组返回的方法。
*/
<?php
//类名与文件名类似
//可连接数据库
//并实现其单类模式,
//还能完成基本mysql模式
//执行普通的增删改非返回结果集的语句
//执行select语句并可以返回3中类型的数据:
//多行结果(二维数组),单行结果(一维数组),单行单列(数据)
class MySQLDB{
public $host; //连接主机
public $port; //连接端口
public $username; //连接用户名
public $password; //连接密码
public $charset; //连接编码
public $dbname; //连接数据库名
private static $link; //实现该类的单例对象
private $resource; //连接数据库返回的资源
//禁止new
private function __construct($config){
/*通过__construct方法来将所需连接数据库信息传入
*/
$this->host = isset($config['host']) ? $config['host'] : 'localhost';
$this->port = isset($config['port']) ? $config['port'] : '3306';
$this->username = isset($config['username']) ? $config['username'] : '