这个是我写的
include("db.php");
$db=new db("localhost","root","","数据库名");
$db->dbConn();
mysql_query("set names utf8");
?>
class db
{
private $host;
private $user;
private $pwd;
private $db;
private $addtime;
function db($host,$user,$pwd,$db)
{
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->db=$db;
}
function dbConn()
{
@mysql_connect($this->host,$this->user,$this->pwd) or die("连接数据库出错!");
@mysql_select_db($this->db) or die("所用数据库不存在!");
}
function dbQuery($sql)
{
$result=@mysql_query($sql) or die(mysql_error());
return $result;
}
function intoArray($result)
{
$row=@mysql_fetch_array($result);
return $row;
}
function totalRows($result)
{
$tRows=@mysql_num_rows($result);
return $tRows;
}
}
?>