特征工程特征工程07-14 03:42

php mysqli类

class mysqlli_db
{

var $db_connect_id;
var $query_result;
var $row = array();
var $rowset = array();
var $num_queries = 0;

//
// Constructor
//
function __construct($sqlserver, $sqluser, $sqlpassword, $database)
{

$this->user = $sqluser;
$this->password = $sqlpassword;
$this->server = $sqlserver;
$this->dbname = $database;


$this->db_connect_id = mysqli_connect($this->server, $this->user, $this->password,$this->dbname);


if ($this->db_connect_id) {
mysqli_set_charset($this->db_connect_id, "utf8");
return $this->db_connect_id;
} else {
return false;
}
}

//
// Other base methods
//
function sql_close()
{
if($this->db_connect_id)
{
if($this->query_result)
{

mysqli_free_result($this->query_result);
}
$result = mysqli_close($this->db_connect_id);
return $result;
}
else
{
return false;
}
}

//
// Base query method
//
function sql_query($sql = "")
{
$this->sql_freeresult();
if ($sql != "") {
$this->query_result = mysqli_query($this->db_connect_id, $sql);
if($this->query_result==false)
{
writelog("SQL : ".$sql."\r\nERROR : ".mysqli_error($this->db_connect_id));
return false;
}
}
if ($this->query_result)
{
return $this->query_result;
}
return false;
}
//
// Other query methods
//
function sql_numrows($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = mysqli_num_rows($query_id);
return $result;
}
else
{
return false;
}
}
function sql_affectedrows()
{
if($this->db_connect_id)
{
$result = mysqli_affected_rows($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
function sql_numfields($query_id = 0)
{
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = mysqli_num_fields($query_id);
return $result;
}
else
{
return false;
}
}

function sql_fetchrow($sql = '',$result_type = MYSQLI_BOTH)
{
if ($sql=='')
{
return false;
}
$this->sql_query($sql);
if($this->query_result)
{
return mysqli_fetch_array($this->query_result,$result_type);
}
else
{
return false;
}
}
function sql_fetchrowset($sql = '',$result_type = MYSQLI_BOTH)
{
if($sql=='')
return false;
$this->sql_query($sql);
if($this->query_result)
{
return mysqli_fetch_all($this->query_result,$result_type);

}
else
{
return false;
}
}

function sql_rowseek($rownum, $query_id = 0){
if(!$query_id)
{
$query_id = $this->query_result;
}
if($query_id)
{
$result = mysqli_data_seek($query_id, $rownum);
return $result;
}
else
{
return false;
}
}
function sql_nextid(){
if($this->db_connect_id)
{
$result = mysqli_insert_id($this->db_connect_id);
return $result;
}
else
{
return false;
}
}
function sql_freeresult($query_id = 0){
if(!$query_id)
{

$query_id = $this->query_result;
}

if ( $query_id )
{

mysqli_free_result($query_id);

return true;
}
else
{
return false;
}
}
function sql_error($query_id = 0)
{
$result["message"] = mysqli_error($this->db_connect_id);
$result["code"] = mysqli_connect_errno($this->db_connect_id);

return $result;
}
function __destruct()
{
$this->sql_close();
}
}

程序之家二维码

000
评论