<?php
class db{
/** 数据库连接指针 */
var $link_id;
/** 返回记录条数 */
var $num_rows;
/** 命令请求指针 */
var $query_id;
/** 返回命令请求影响的列数 */
var $affected_rows;
/** Constructed function
* @ Trait : create a connection for database */
function __construct($rData)
{
$dbAddr = $rData[0];
$dbBName = $rData[1];
$dbBUser = $rData[2];
$dbBPass = $rData[3];
$this -> link_id = @mysql_pconnect($dbAddr, $dbBUser, $dbBPass) or die ($this-> link_id = "Mysql connection unsuccessful!");
$selectDB = @mysql_select_db($dbBName, $this -> link_id) or die ($this-> link_id = "Database select unsuccessful!");
mysql_query("set names 'utf8'");
return $this -> link_id;
}
/** Close database connection
* @ Parameter : $link_id - database link pointer
* @ Trait : release database link pointer */
function Quit($link_id){
mysql_close($this->link_id);
}
/** Release pointer
* @ Parameter : $query_id - pointer
* @ Trait : release pointer */
function free_result($query_id){
@mysql_free_result($query_id);
}
/** execute SQL
* @ Parameter : $sql_str - SQL语句
* @ Trait : return a singleness Array */
function Query($sql_str){
$this->query_id = @mysql_query($sql_str, $this -> link_id);
$this->num_rows = @mysql_num_rows($this->query_id);
$RS=@mysql_fetch_array($this->query_id,MYSQL_ASSOC);
if ($this->num_rows == 0) {
$RS = FALSE;
}
$this->free_result($this->query_id);
return $RS;
}
/** execute SQL
* @ Parameter : $sql_str - SQL语句
* @ Trait : return a multidimensional Array */
function Query_array($sql_str){
$this->query_id = @mysql_query($sql_str, $this -> link_id);
$this->num_rows = @mysql_num_rows($this->query_id) ;
if ($this->num_rows == 0) {
$RSarray = FALSE;
$this->free_result($this->query_id);
return $RSarray;
}else{
for($i=0;$i<$this->num_rows;$i++){
$RSarray[$i]=mysql_fetch_array($this->query_id,MYSQL_ASSOC);
}
$this->free_result($this->query_id);
return $RSarray;
}
}
/** execute SQL
* @ Parameter : $sql_str - SQL语句
* @ Trait : none data return */
function Query_noreturn($sql_str){
$this->query_id = mysql_query($sql_str, $this -> link_id);
$this->affected_rows = @mysql_affected_rows();
$this->num_rows = mysql_insert_id();
if ($this->query_id){
$RS = TRUE;
return $RS;
}else{
$RS = FALSE;
return $RS;
}
}
function getQueryID()
{
return $this->num_rows;
}
}
?>
|