views:

716

answers:

5

Hello everybody.

Just got developing with Flex, and i like it.

I've done some simple apps to get the felling of it, nothing involving updating a file or a database.

I wanted help, how to do a query to a MySql DB from a Flex application (thats gonna be running in a web server).

I didn't saw any duplicated questions, sorry if any exists, just point me to it.

EDIT:

Using PHP to do the query on the server.

::

Thanks for any help.

+1  A: 

Flex applications are not run on the server, they are run on the client. You do not want them accessing your database directly, and thusly, they generally can't.

The DB update should be done in the server side code/language.

stevedbrown
Yes your right, this is kinda like Ajax, i suppose. I could i do that using the Flex app and PHP ?
Fábio Antunes
+2  A: 

While I've never done this myself I have read and watched tutorials about it. The tutorial can be found here and the one in particular is labeled "Integrating Flex with PHP using XML" and is at the bottom of the page.

http://www.adobe.com/devnet/flex/videotraining/

It basically outlines how to use Flex's HTTPService to interact with a PHP script. This PHP script can be used to communicate directly between your flash application and your mysql database using GET and POST vars.

justinl
This url gived me guidance how to perform that HTTPService request. I pretty sure i can do it now. Thanks.
Fábio Antunes
And yes I've done it. Thanks guys.
Fábio Antunes
Great to hear!
justinl
+2  A: 

Hello.

From flex you cannot access directly a database on a server. For that you need a webservice on the database server which will act as a middle-tool between your Flex app and the database.

So practically you will have on the webservice some webmethods which will do the queries for flex and return the results to it.

As a example: You have a webmethod called loginUser(username,passwprd):bool. You call this method from flex, the method checks the database and returns a Boolean value representing the success result of the login.

You can create webservices for Flex apps with php c# java and so on... just need to google about them. :)


Adrian

Adrian Pirvulescu
Greatly appreciated for you info about using other than PHP/ASP... scripts to do the server side work, i didn't know that C# could also do it. Thanks
Fábio Antunes
+1  A: 

Take a look at AMFPHP also. This is a pretty good way to serialize data between PHP and your Flex front end. AMFPHP also has built in methods for handling user sessions to maintain security. I use it at work to let our Flex app access our back end database.

As far as file access, I think you need to create an AIR application to have access to the File class. Flex isn't allowed access to the local file system for security purposes.

ryanday
Really Good indeed. But i only will use it once i now, the ordinary/usual way of doing it. But I've looked into the code, and its very good, simple and easy to implement. My thanks.
Fábio Antunes
And seems the best way to return data from Sql. I will be using it for sure.
Fábio Antunes
+1  A: 

You could think about using a restful service if your using PHP, as this wouldn't need you to learn complicated web services and SOAP stuff. Put your requests in the query string of the php file i.e.

www.myserver.com/getproductprice.php?id=23&quanity=2312

then all you need to do is get the values from the url in php

id = $_GET['id'];  //(my php is not too good!!!)
id = $_GET['quanity'];

then go off and do you db query in php. this could then return you either text or xml. It's simpler model to get going it your just starting out.

hope this helps

Jon
Another way of doing it. Nice thanks. Thats what I'm going for. "Ways of doing it".
Fábio Antunes