課程
/后端開發(fā)
/PHP
/大話PHP設(shè)計模式
為什么我不能通過$u->name去獲取name的數(shù)據(jù)
2016-08-21
源自:大話PHP設(shè)計模式 12-1
正在回答
<?php namespace?IMooc; class?User { ????//數(shù)據(jù)庫表 ????public?$id; ????public?$name; ????public?$mobile; ????public?$regtime; ????public?$seril_no; ????protected?$data; ????protected?$db; ????function?__construct($id) ????{ ????????/** ?????????*?適配器模式-統(tǒng)一接口 ?????????*?工廠模式,在一個地方創(chuàng)建對象 ?????????*?注冊樹模式,同一個對象,只創(chuàng)建一次 ?????????*/ ????????$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']; ????} ????//析構(gòu)方法 ????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中這樣寫,應(yīng)該可以取出來
Hong林偉本以為 提問者
老師課上講的這種獲取方式是使用了 對象映射模式,看看你的代碼是不是這樣做的
舉報
幫助PHPer具備使用設(shè)計模式解決工程中復(fù)雜邏輯的能力
3 回答命名空間不支持new $name()這樣的實例化么,還是不支持new \func\$name(),路徑不能解析?
3 回答為什么我的phpstrom不能run額
2 回答為何我的數(shù)據(jù)庫沒有自動增加所寫的數(shù)據(jù)?
5 回答最后執(zhí)行$user->serial_no=rand(1000,90000); 為什么能保存到數(shù)據(jù)庫???
1 回答請問,獲取數(shù)組的key的時候是不是就自動調(diào)用了offsetget 方法呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-10-05
user中這樣寫,應(yīng)該可以取出來
2016-08-27
老師課上講的這種獲取方式是使用了 對象映射模式,看看你的代碼是不是這樣做的