public $conn; //数据库连接变量
/**
* DB 类构造函数
*/
public function DB($host=DB_HOST ,$username=DB_USER,$password=DB_PASSWORD,
$dbname=DB_NAME)
{
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->dbname = $dbname;
}
/**
* 打开数据库连接
*/
public function open()
{
$this->conn = mysql_connect($this->host,$this->username,$this->password);
mysql_select_db($this->dbname);
mysql_query("SET CHARACTER SET utf8");
}
/**
* 关闭数据连接
*/
public function close()
{
mysql_close($this->conn);
}
/**
* 通过 sql 语句获取数据
* @return: array()
*/
public function getObjListBySql($sql)
{
$this->open();
$rs = mysql_query($sql,$this->conn);
$objList = array();
while($obj = mysql_fetch_object($rs))
{
if($obj)
{
$objList[] = $obj;