日期:2014-05-17  浏览次数:20467 次

关于查询返回实体的问题
//实体类
PHP code
 class Newes
   {
   //var advertisingid;
   //var adcontent;
  
           private int advertisingid;
        private String adcontent;
        private String texttitle;
        private String prclink;
        private String time;
        private String urllink;
        private int newtype;
        private String newlaiyuan;
        public function getId()
        {
            return $this->advertisingid;
        }
        public function setId($advertisingid)
        {
            $this->advertisingid=$advertisingid;
            return $this;
        }
        public function getAdcontent()
        {
            return $this->adcontent;
        }
        public function setAdcontent($adcontent)
        {
            $this->adcontent=$adcontent;
            return $this;
        }
        public function getTexttitle()
        {
            return $this->texttitle;
        }
        public function setTexttitle($texttitle)
        {
            $this->texttitle=$texttitle;
            return $this;
        }
    
   }

处理方法
PHP code

$sql="select * from newes where advertisingid =1";
$abc =mysql_query($sql);
/**
while($num =mysql_fetch_array($abc))
{
    $num
}
*/


问:就是用什么方法返回一个实体类
比如 Newes $newes = new Newes();
$newes =mysql_query($sql); //这样子就是返回一个实体类么?
超级新手迷糊中····请帮忙解释一下 谢谢

------解决方案--------------------
两段代码之间有神马关系??
第一个返回实体类
第二个mysql_query返回resource类型的结果集
------解决方案--------------------
形如: private int advertisingid; 改为 private $advertisingid;

你那套是java里面的定义方法吧。
------解决方案--------------------
mysql_fetch_row()
mysql_fetch_array()
mysql_fetch_assoc()

具体区别,请谷歌查。