Kirthivasan
Kirthivasan

Reputation: 31

connecting to mysql using php in flex

Hi I am new to flex, I wanted to use flex line chart for displaying data stored in mysql table. Can anyone suggest me on how do I do this with flex as UI and mysql as db, I am not sure how to call .php file in flex to query from mysql. I wanted to show some data of time v/s temperature

I wrote a php file to query data from mysql, but my flex program is not able to connect to mysql, is there any configuration I need to update. I am using XAMPP

Upvotes: 1

Views: 800

Answers (1)

shaunhusain
shaunhusain

Reputation: 19748

Generally speaking theres no extra configuration you need to make this work as hering said in the comment an HTTPService will serve your purposes. Here's what you need to do:

private var myCollection:ArrayCollection;

public function creationComplete(event:Event):void
{
    var myService:HTTPService = new HTTPService();
    myService.url = "myscript.php"
    myService.method = "POST";
    myService.addEventListener(ResultEvent.RESULT, resultHandler);
    myService.send();
}

public function resultHandler(event:ResultEvent):void
{
    if(event.result..entries is ArrayCollection)
        myCollection = event.result..entries;
    else if(event.result..entries is Object)
        myCollection = new ArrayCollection(event.result..entries)
}

I'm assuming you're adding a listener to whatever control this service call lives in for creation complete that calls the creation complete function. I also assume you have (php generate) an xml structure like:

<entry>
    <entries>1</entries>
    <entries>2</entries>
</entry>

Upvotes: 1

Related Questions