這是一款簡單實用的php連接mysql數據庫類了,只做了數據查詢,返回數組集,獲取新的id 取得記錄行等簡單的mysql數據庫連接代碼。
*/
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.111cn.net
function close() {
mysql_close($this->dblink);
}
}//調用 方法
$db = new database;
$db->connect($dbhost, $dbuser, $dbpw, $dbname);
unset($dbhost, $dbuser, $dbpw, $dbname);
?>