为什么我不能通过$u->name去获取name的数据
<?php namespace IMooc; class User { //数据库表 public $id; public $name; public $mobile; public $regtime; public $seril_no; protected $data; protected $db; function __construct($id) { /** * 适配器模式-统一接口 * 工厂模式,在一个地方创建对象 * 注册树模式,同一个对象,只创建一次 */ $this->db = \IMooc\Factory::createDBMySQLi(); $this->db->connect('localhost', 'root', '', 'test', 'utf8'); $res = $this->db->query("select * from user where id = {$id} limit 1"); $data = $res->fetch_assoc(); $this->id = $data['id']; $this->name = $data['name']; $this->mobile = $data['mobile']; $this->regtime = $data['regtime']; $this->seril_no = $data['seril_no']; } //析构方法 function __destruct() { $this->db->query("update user set name ='{$this->name}', mobile='{$this->mobile}', regtime='{$this->regtime}', seril_no='{$this->seril_no}' where id = {$this->id} limit 1"); } }
user中这样写,应该可以取出来
老师课上讲的这种获取方式是使用了 对象映射模式,看看你的代码是不是这样做的