欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

flex连接mysql数据库

程序员文章站 2022-04-29 23:42:45
...
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
  xmlns:mysql="com.maclema.mysql.mxml.*">
  <mx:Script>
   <![CDATA[
    import mx.controls.Alert;
    import com.maclema.mysql.events.MySqlErrorEvent;
    import com.maclema.mysql.mxml.MySqlService;
    import com.maclema.util.ResultsUtil;
 
    private function sendToMysql():void{
     service.send("SELECT * FROM user_table");    
    }
    private function handleError(e:MySqlErrorEvent):void{
      Alert.show(e.msg);
    }
   ]]>
  </mx:Script>
 <mysql:MySqlService  id="service"
   hostname="localhost" port="3306" username="root" password="123" 
   database="db_connect" autoConnect="true" connect="sendToMysql()" 
   sqlError="handleError(event)" />
 
  <mx:DataGrid id="grid"  width="300" dataProvider="{service.lastResult}"
                columns="{ResultsUtil.getDataGridColumns(service.lastResultSet)}" />
 
</mx:Application>