<?php
class entity_site
{
private $SiteID;
private $SiteName;
private $SiteUrl;
private $SiteContactInfo;
private $SiteAudit;
private $SiteElite;
private $SiteClassID;
public function __get($PropertyName)
{
return($this->$PropertyName);
}
public function __set($PropertyName, $Value)
{
$this->$PropertyName = $Value;
}
}
?>
那么假设我现在把从数据库中获取的记录集放在数据$arr里面,我应该怎么实现?
我的思路是:
遍历记录集
{
遍历字段
{
如果(实体属性中有和字段名相等的))
{
实体的属性 = $row[$field](这条记录的字段的值)。
}
}
}
请赐教。具体语法不知道怎么写,谢谢!

解决方案 »

  1.   

    如果用pdo的话可以用那个bindParam
      

  2.   

    给你点意见;这是实体吧。class  DeptMain{
    private $DeptID;
    private $DeptName;
    private $DeptNameEn;
    private $IsBiz;
    private $IsGZ;
    private $FirstChar;
    private $IsDel;
    function __construct($DeptID,$DeptName,$DeptNameEn,$IsBiz,$IsGZ,$FirstChar,$IsDel){
    $this->DeptID=$DeptID;
    $this->DeptName=$DeptName;
    $this->DeptNameEn=$DeptNameEn;
    $this->IsBiz=$IsBiz;
    $this->IsGZ=$IsGZ;
    $this->FirstChar=$FirstChar;
    $this->IsDel=$IsDel;
    }
    function __get($var){
    return $this->$var;
    }
    }这是类似的结果集;之后循环,实例化那个实体类
    if(count($DeptMains)>0){
    foreach ($DeptMains as $DeptMain){
    $Dept[]=new DeptMain($DeptMain['DeptID'],$DeptMain['DeptName'],$DeptMain['DeptNameEn'],$DeptMain['IsBiz'],$DeptMain['IsGZ'],$DeptMain['FirstChar'],$DeptMain['IsDel']);
    }
      

  3.   

    你刚取出来存数组的时候就把标注弄好
    $resArr = array();
    $resArr['name'] = $rows['name'];//假设有这个name字段
    $resArr['age'] = $rows['age'];
    class中加 
    var $name;
    var $age;
    function __construect($name,$age){
    $this->name = $name;
    $this->age = $age;
    }
    ......
    $obj = new example($resArr['name'],$resArr['age']);
      

  4.   

    那试问PHP里面有没有像.NET里面的list<Entity>呢?
    将记录集放入list里面。
      

  5.   

    mysql的例子
    http://www.php.net/manual/en/function.mysql-fetch-array.php
      

  6.   

    php里面现在不存在实体这一概念。MVC里面没有实体一说