 <?php
 /*
    获取当前页数据类 　
    version：1.0
    author：侯爷的博客
    www.palmcivet.ren
    Date：2016-5-21
    */
    
    /*调用示例
$sql = "select * from product where pid=1";
$mypage = new getcurdata($sql);
$mydata = $mypage->getdata();
if($mydata){
echo "ID号：".$mydata->pid."<br>";
echo "名称：".$mydata->pname."<br>";
echo "共有：".$mypage->getfields()."列";
}
    */
 
class getcurdata{
	
	private $getfields;
  private $result;
  private $pdata;
  private $psqlstr;//查询的SQL语句
 
function __construct($psqlstr){
$result = mysql_query($psqlstr) or die('查询数据错误:'.mysql_error());
$pdata = mysql_fetch_object($result);
$this->psqlstr = $psqlstr;
$this->result = $result;
$this->pdata = $pdata;
}

//返回记录集总列数
 function getfields(){
$this->getfields = mysql_num_fields($this->result);
return $this->getfields;
	}
//返回当前数据
 function getdata(){
 	if($this->pdata){
return $this->pdata;
}else{
echo "<script>alert('查询ID号失败');</script>";
return false;
	}
	}

}
    ?>