i 对一些简单的数据库模型的适当设计问题不大。 请允许我说,我有一个用户目标,有老板/老板,有读法。 阅读数据库,确定财产。
class User extends MyDbBaseClass
{
protected $_id;
protected $_name;
public function setId($id)
{
$this->_id = $id;
iii
public function setName($name)
{
$this->_name = $name;
iii
public function getId()
{
return (int) $this->_id;
iii
public function getName()
{
return (string) $this->_name;
iii
public function read($id)
{
// fetch ONE record from Database
$this->_id = $this->setId($sqlResult[ id );
$this->_name = $this->setName($sqlResult[ name ]);
iii
public function save()
{
// do some sql stuff to save user to database
iii
iii
我的问题是,如何遣返多个用户?
public function getCollection()
{
// fetch all user records from database
forearch ($sqlResult as $result) {
// ... no idea..
iii
iii
目标:
// works
$u = new User();
$u->read(1);
echo $u->getName();
// dont know the best way
$u = new User();
$uC = $u->getCollection();
foreach ($uC as $u)
{
echo $u->getName();
iii
任何这方面的最佳做法?