
how to connect Mysql database with flash via php?
I want to connect my fla file with mysql database via php.
How can I do that, please help me with an example.
You don’t get to actually connect the db from actionscript but what you will do is make requests from actionsctipt to a php script that will do the data processing for you.
var request:URLRequest = new URLRequest(“http://www.yourserver.com/dataLayer.php”);
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(request);
function completeHandler(evt:Event) {
var username = evt.target.data.username;
var email = evt.target.data.email;
trace (‘username is ‘ + username);
trace (‘email is ‘ + email);
}
this is an AS example. In the file dataLayer.php you will have to process anything db-related, make your connection, queries, etc. In order to have the variables available in AS, you will have to echo a query string (in GET format – var1=value1&var2=value2 … and so on). After that in the callback function called “completeHandler” you will have the variables ready to use.
The whole thing is very similar to AJAX, calls are asynchronous so the script will continue running even as the request to php is made. You don’t know when the request will be complete, but you know that whenever that may happen, the callback function will be triggered.