<?php
header('Content-Type: text/html; charset=utf-8');
class mysql {
//定义属性
private $host = '';
private $user = '';
private $password = '';
private $tables = '';
private $coding = '';
//构造方法
function __construct($host,$user,$password,$tables,$coding){
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->tables=$tables;
$this->coding=$coding;
$this->connect();
}
//链接MySQL方法
function connect($host,$user,$password,$tables,$coding){
$conn = mysql_connect($host,$user,$password) or die("连接服务器错误");
mysql_select_db($tables,$conn) or die(mysql_error());
mysql_set_charset($coding);
}
//简化函数mysql_query为query
function query($v){
return mysql_query($v);
}
function fetch_array($a){
return mysql_fetch_array($a);
}
}
$db = new mysql(localhost,root,"",table,utf8);
?>