0

I have a MySQL database, and i created a DB and named it 'PERSONDB'. Within that DB, i have created a table and named it Person. This table has 3 fields. id,name,age.

Now i need to save some values from my flex website to the mySQL 'PERSONDB' that i created.

How can i do this in Flex (Flax builder 4.6)

Note: I have added 2 fields name and age, in the Flex project and when the user clicks on the Button i need those values to be saved in the DB. how can i do this.

Illep
  • 16,375
  • 46
  • 171
  • 302
  • As per my info: - You can do this by using Serverside language (By using java/.net as mediator). Flex does not support it directly. Client -> Server -> DB and vice versa to get data from DB to Client. – Mahesh Parate Jun 21 '12 at 09:32
  • Is there any examples/tutorial/code available just to create a basic application (Connect to a Java service). So i could understand it ? – Illep Jun 21 '12 at 09:47
  • You can find n number of example on net. Right now i don't have such example. – Mahesh Parate Jun 21 '12 at 10:35

1 Answers1

0

asSQL ( http://code.google.com/p/assql/ ) is a good approach to using mySQL. It allows for direct access to mySQL from any application either in AIR or web based. I use this pretty regularly in my coding so I don't have to write a Java or PHP as a back end unless there is a good reason to have a back end in place.

OK, here is the code I use:

    <assql:MySqlService id         ="DB"
                        hostname   ="localhost"
                        username   ="user"
                        password   ="password"
                        database   ="db"
                        autoConnect="true"
                        connect    ="handleConnected(event)"
                        sqlError   ="handleError(event)"/>


        private function getSelectedData() : void
        {
            DB.send("SELECT * from table WHERE number = '" + number.text + "'");
        }

That's all there is too it. The top part sets up the connection and is in the section of the code. The rest is in the part (ActionScript). Of course, it can be done in straight ActionScript as well, but this solution used MXML.

powelljf3
  • 119
  • 4
  • Is it still stable ? because the last update was made back in 2010 :S – Illep Jun 21 '12 at 17:29
  • I have had no issues with it. It was stable when the Beta was put up, but plans were to continue at the time. – powelljf3 Jun 21 '12 at 17:38
  • But still you need to add Java code according to http://ntt.cc/2008/02/01/actionscript-mysql-driver-assql-access-database-from-flex.html . How can i do this if so ? – Illep Jun 21 '12 at 17:39
  • Added an example for you on how it is coded for direct access. Once it is connected, you just call the service with the query you want to use. Also in this example, handleConnected simply calls another method which does a query once connected. – powelljf3 Jun 21 '12 at 17:55