欢迎来到天天文库
浏览记录
ID:37489381
大小:51.50 KB
页数:9页
时间:2019-05-24
《AS3链接MySqL》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、AS3连接MYSQL数据库最近由于制作任务编辑器,需要连接到数据库中进行一些任务数据的操作,而我们存放任务数据的数据库中MYSQL,所以就找了一下AS3接连MYSQL数据库的资料。找到一个好东西:ActionScript3MySqlDriver,用SVN的童鞋可以直接checkout:http://assql.googlecode.com/svn/trunk/为了使用简单,我做了一个简单的包装类(包含一个数据结构):viewsourceprint?packagecom.easily.ds{publicclassDataBaseData{publicvarhost:
2、String;publicvarport:int;publicvarusername:String;publicvarpassword:String;publicvardatabase:String;}}viewsourceprint?packagecom.easily.util{importcom.easily.ds.DataBaseData;importcom.maclema.mysql.Connection;importcom.maclema.mysql.Field;importcom.maclema.mysql.MySqlResponse;importco
3、m.maclema.mysql.MySqlToken;importcom.maclema.mysql.ResultSet;importcom.maclema.mysql.Statement;importflash.events.Event;importflash.events.EventDispatcher;importmx.rpc.AsyncResponder;/***@authorEasily*/publicclassDataBaseextendsEventDispatcher{privatevarmDataBase:DataBaseData;privatev
4、armConnection:Connection;publicfunctionDataBase(database:DataBaseData){mDataBase=database;}publicfunctionconnect():void{mConnection=newConnection(mDataBase.host,mDataBase.port,mDataBase.username,mDataBase.password,mDataBase.database);mConnection.addEventListener(Event.CONNECT,onConnec
5、ted);mConnection.connect();functiononConnected(event:Event):void{mConnection.removeEventListener(Event.CONNECT,onConnected);dispatchEvent(event);}}publicfunctiondisconnect():void{mConnection.disconnect();}publicfunctionselect(sql:String,completeHandler:Function,errorHandler:Function=n
6、ull):void{varst:Statement=mConnection.createStatement();vartoken:MySqlToken=st.executeQuery(sql);varresponder:AsyncResponder=newAsyncResponder(resultHandler,faultHandler,token);token.addResponder(responder);functionresultHandler(result:Object/*ResultSet*/,token:Object/*MySqlToken*/):v
7、oid{vardata:Array=[];if(resultisResultSet){varfieldList:Array=result.getColumns();while(result.next()){varitem:Object={};foreach(varfield:FieldinfieldList){item[field.getName()]=result.getString(field.getName());}data.push(item);}}completeHandler(data);}functionfaultHandler(info:Objec
8、t,tok
此文档下载收益归作者所有