代码如下 | 复制代码 |
class database { var $dblink; function connect($dbhost, $dbuser, $dbpw, $dbname = "") { $this->dblink = mysql_connect($dbhost, $dbuser, $dbpw); mysql_query("set names 'utf8'"); mysql_query("set character_set_client=utf8"); mysql_query("set character_set_results=utf8"); if($dbname) { mysql_select_db($dbname, $this->dblink); } } function query($sql) { $result = mysql_query($sql, $this->dblink); return $result; } function fetch_array($result) { return mysql_fetch_array($result); } function insert_id() { $id = mysql_insert_id(); return $id; } function getrow($sql) { $result = mysql_query($sql, $this->dblink); return mysql_fetch_assoc($result); } function getdetailrow($sql) { $result = mysql_query($sql, $this->dblink); return mysql_fetch_array($result); } //www.111com.net function close() { mysql_close($this->dblink); } } |
//调用 方法
代码如下 | 复制代码 |
$db = new database; $db->connect($dbhost, $dbuser, $dbpw, $dbname); unset($dbhost, $dbuser, $dbpw, $dbname); |
?>