class clsDB {
var $c;
var $rs;
var $result;
var $lastSql;
var $rowPerPage;
var $frRowNum;
var $toRowNum;
var $numRows;
var $DB;
function AddNew(){
$this->status = 1;
}
function Edit(){
$this->status = 2;
}
function Save(){
//--1 เป็นข้อมูลใหม่ 2 เป็นข้อมูลเดิม --Must Overrided
}
function Delete(){
//--ใช้เมธอดนี้เพื่อลบข้อมูลเดิมในอ๊อบเจ๊ก เป็นการลบข้อมูลทีละ 1 เรคอร์ด
//--ต้องเรียกเมธอดตามลำดับดังนี้ SearchByKey()-->GetRecord()-->Delete()
//--Must Overrided
}
function Close(){
return mysql_free_result($this->rs);
}
function SetQuery($query){
$this->lastSql=$query;
mysql_select_db($this->DB);
//echo "-$this->DB=";
$this->rs= mysql_query($query);
if (!$this->rs){
die("
เกิดข้อผิดพลาด |
" . mysql_errno() . " : " . mysql_error() . "
$query |
");
}
$this->numRows = $this->GetRowSelected();
return $this->rs;
}
function SetQueryPage($query){
mysql_select_db($this->DB);
$this->rs= mysql_query($query);
if (!$this->rs){
die("
เกิดข้อผิดพลาด |
" . mysql_errno() . " : " . mysql_error() . "
$query |
");
}
return $this->rs;
}
function Dml($query){
mysql_select_db($this->DB);
if (!mysql_query($query)){
die("
เกิดข้อผิดพลาด |
" . mysql_errno() . " : " . mysql_error() . "
$query |
");
}
return mysql_affected_rows();
}
function GetResult(){
if ($this->rs){
$this->result = mysql_fetch_array($this->rs);
return $this->result;
}
return 0;
}
function GetResultValue($Atb){
return $this->result["$Atb"];
}
function GetRowSelected(){
return @mysql_num_rows($this->rs);
}
function GetLastInsertID(){
return mysql_insert_id();
}
function NumField(){
return mysql_num_fields($this->rs);
}
function numPages() {
return ceil($this->numRows/$this->rowPerPage);
}
function gotoPage($pg=1){
if ($this->lastSql<>""){
$this->frRowNum=($pg-1)*$this->rowPerPage;
$sql = $this->lastSql." limit $this->frRowNum, $this->rowPerPage";
$this->SetQueryPage($sql);
}else{
die("
เกิดข้อผิดพลาด |
ยังไม่ได้สร้างคำสั่ง Select |
");
}
}
}
?>