资源描述:
《ecmall关于数据查询缓存的问题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、ECMallquestionsaboutdataquerycachingShortlyaftertheseconddevelopmentoftheEcmall,Ireceivedatask.Themostcommontasksaretodosomeoperationsonthedatabase,wherethequerymethodiswrittenlikethis:Functiongetorderdata($goodsid)Ineludeonce(“gonndb/nmd・php“);Ineludeonce(“gonndb/dbin
2、fo・PHP“);$connector=newNMDB($host,$username,Spassword);$connector-〉selectdb($database);$SQL="selecta.buyername,a.addtime,a.status,b.phone_tel,b.phone_mob,c.price,c.quantity.Fromshopordera,shoporderextmb,shopordergoodscWherea.orderid=b.o.rderidandb.o.rderid=c.o.rderid〃A
3、ndc.goods_id二〃.$goods_id.Theorderbya.addtimedescLimit3Sresult二$connector->query($SQL);//$r=array();While($myrow二$connector-〉fetch_array(Sresult)$r[]二$myrow;Return$r;Thedataforthefirstqueryiscorrect,andthenthedatathatisparsedbythetemplateisincorrect・Itwasdiscoveredthatt
4、heEcmallhadsuchamechanism・Firstafterappfordatabaseoperation,afteroperationcanleaveunderthetemp/compileed/stencilbuffer,andafterthefirstdatabasequerydatabasecache・Thisshowsthattheseconddevelopmentisbestnottouseyourowndatabasefunction,butit'sbettertousetheEcmal1.Theabove
5、methodischanged:Functionget_order_data($goods_id)$db二&db();$SQL二"selecta.buyer_name,a.add_time,a.status,b.phone_tel,b.phone_mob,c.price,c.quantity・Fromshop_ordera,shop_order_extmb,shop_order_goodscWherea・order_id二b・o.rder_idandb・o.rder_id=c・o.rder_id〃Andc.goods_id二〃.$g
6、oods_id・〃Theorderbya.add_timedescLimit3“;Sresult=$db->query($SQL)$r二array();While($myrow二$db->fetch_array(Sresult){$r[]二$myrow;}Return$r;ThisfunctionsimplyUSESthedatabasefunctionbroughtbytheEcmall,ordoesnotproduceadatabasecache・Ifyoulookatsomeoneelse,howdoyougeneratead
7、atabasecache?Here,saprogramfortheannouncement:
8、e_server二&cache_server0;//gettheidofthecachedobjectdata$key二$this->_get_cache_id()//thereceiptofthepartysecretary$dat