Over a million developers have joined DZone.

PHP: Connecting Flash To A Database (remoting)

There are many ways to do this.

Depending on the backend language you're using, whether PHP, ColdFusion or other... you'll need to create some components (CFC's for ColdFusion), (Classes for PHP)... these are referred to as "services"

Then you'll need to connect Flash to a remoting gateway (I use AMFPHP for PHP: www.amfphp.org).

Either way, you'll need NetServices.as from Flash MX Remoting, call a gateway and retrieving a list of functions from your classes/components/services.

Enough with the theory, here's how to do it with PHP:

/* /flashservices/services/Catalog.php */
class Catalog {
        var $products_array = array();

// Constructor: Contains the list of methods available to the gateway
function Catalog() {
	$this->methodTable = array (
		"getProducts" => array (
			"description" => "Get list of products",
			"access" => "remote",
			"arguments" => "" // arguments could be optional, not tested
	); // end methodTable

function getProducts() {	
	// your code goes here

	return $this->products_array;

!!!!!!!!! The code below is now deprecated !!!!!!!!
---- see my other snippet to do this in Flash 8 ----

Flash ActionScript (PHP Gateway):

#include "NetServices.as"
gw = NetServices.createGatewayConnection();
CatalogREMOTE = gw.getService("Catalog", this);

getProducts_Result = function(result) {
	_root.products_results = result;

You parse the _root.products_results array however you want :D

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}