<?php
header("Content-type:text/html;charset=utf-8");
class DBUtils{
private $ychat_host = "localhost";
private $ychat_username = "root";
private $ychat_password = "123456";
private $ychat_database = "m";
private $conn;
function __construct(){
$this->connect();
}
function dbClose(){
mysql_close($this->conn);
}
function connect(){
$this->conn = mysql_connect($this->ychat_host,$this->ychat_username,$this->ychat_password)
or die ("connection MySQL failed!");
mysql_select_db($this->ychat_database,$this->conn);
mysql_query("set names utf8");
}
//对mysql_query()、mysql_fetch_array()、mysql_num_rows()函数进行封装
function query($sql){
return mysql_query($sql);
}
function myArray($result){
return mysql_fetch_array($result);
}
function rows($result){
return mysql_num_rows($result);
}
//自定义查询数据方法
function select($table,$tablename,$condition){
return $this->query("SELECT $tablename FROM $table $condition");
}
function insert($table,$fields,$value){
$this->query("INSERT INTO $table ($fields) VALUES ($value)");
}
function update($table,$change,$condition){
$this->query("UPDATE $table SET $change $condition");
}
function delete($table,$condition){
$this->query("DELETE FROM $table $condition");
}
}
?>