<?php
// 数据库操作类MySQLDB
class MySQLDB {
// 声明属性
private $server;
private $username;
private $password;
public $default_db;
public $link;
// 声明构造函数
public function __construct($server,$username,$password,$default_db) {
// 设置连接字符串
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->default_db = $default_db;
// 连接数据库
$this->link = mysql_connect($this->server,$this->username,$this->password);
if (!$this->link) {
echo ‘database connect failure!‘;
}
// 设置默认的数据库
$bool = mysql_select_db($this->default_db,$this->link);
if (!$bool) {
echo ‘Select default_db failure!‘;
}
}
// 声明析构函数
public function __destruct() {
mysql_close($this->link);
}
}
原文地址:http://blog.csdn.net/u014044821/article/details/46337319