Archive for the ‘php’ Tag
Flash Remoting for PHP – Part 2 – Creating my own Service in amfphp (getting data)
After we got the installation working of amfphp we are now going one step further …if you missed it, find it here!
What will we need?
- correct installation of the amfphp service (0n webservice or locally)
- a php editor (personal using Adobe Dreamweaver)
- if using a amfphp installation on a online webserver, a ftp program (using FileZilla)
What is a amfphp service?
Well an amfphp service, is actually a php class that contains one or more function that handle the retrieval of database data
Example files
For a good understanding and following of this tutorial i created folowing database: designz_labs_amfphp with one table: books

Database and Table structure
for this tutorial I recommend using a local verison of amfphp using Mamp (Mac) of Wamp (Windows).
You can download the database file here , so you can follow along with the same information.
Creating the BookService
Now we will create a service that will retrieve all the books in the tabel books
Different steps:
- importing the database and creating a new database user with the right right
- opening the php editor and creating a new php file
- creating a new class BookService
- creating a basic constructor holding the connection details
- creating a new function (method) : getBooks
- calling the php function inside flash using amfPHP
Importing and User creation
importing : on the phpMyAdmin main page you will be able to import a database, do this and according to the .zip file download from above link.
user creation: on the same main page , go to Rights or Privileges and create a new user (user: books , password: books , Host:localhost) and make sure that the user has select and insert rights. This account information will be needed to have the tight privileges on the database table.
Creating a new class: BookService
open up a php editor and create a new php file.
Now create a new class: BookService

Creating the BookService
Creating the basic constructor with database connection data
Now we will add a basic constructor, where we will set connection data (telling the php that we are connection to localhost, with user: books having the password: books) and select database: designz_labs_amfphp for connection.

Creating the Basic Constructor
Creating a new function getBooks
In this peace of php we will add a new function “getBooks” , we select every record in the table “books” , and add all these records to an array … after completion the array will be returned to the amfphp , which will be called in Flash.
Finally save this php file into the amfphp service directory… Now we are ready to call this function from flash and process the results!

getBooks Service
Calling the getBooks function from Flash Actionscript

Calling the getBooks function
We just make a new netconnection and a new responder (that will cary the answer = the database result data) with the answer function when completed.
Via the netconnection we connect to the url of our amfphp (this can be local or on the network), than we call the php file BookService and the function getBooks in that php file … giving it the responder as paramater.
When the function is called with result , the getBooksResult will be called , here we loop through each object in the result array, in this case all the titles of the books ….
Download the source fla here…!
Enjoy … the next tutorial on amfphp will be calling database action combined with custom parameters !
Flash Remoting for PHP – Part 1 – Installing amfphp to webserver
Flash Remoting for PHP ?
Flash remoting allows flash movies to get database data from your system or webserver, without knwoledge of the server side.
without complex code and knowing to much of databases , you will be able to add database connection for receiving and sending data from and towards your database to your Flex / Air / Flash applications.
Advantage?
I can tell you it is fairly easy and time saving , think about XML’s a great while back , i had many stress moments loading tons of data
, the only thing we need is a little bit of know-how.
Which i will give in this first post , starting from the beginnen : the installation
What do we need?
- Webserver with PHP4 ( > 4.3.0 ) or PHP5 installed on it
- PHPMyAdmin installed on the webserver
- amfphp source files : download
- ftp client to upload the amfphp source files (for mac: download here , for windows: download here )
Instructions
Step 1 - Unzip the amfphp download, and upload this folder to the root folder of your personal webspace , make it look something like this

Structure of the amfphp folder
Step 2 – gateway.php is found in the main folder of the source code , there you can change some basic settings, but i never have to do so , standard settings work fine for me .. after installation we will run through a little test , if this fails you might want to read through and change some settings … just making a mention of it!
Step 3 – great, now that the amfphp folder is online … lets test it before we continue …
navigate in the browser to the folowing url:
http://www.[myonlinespace].[myextention]/amfphp/gateway.php
if getting this following screen , it is telling you that you are set … installation OK!

Install Succesfull
So will it work?
Just to make sure all settings are done correct: Lets click on “Load the service browser“
After everything is loaded and displayed, you will see something like this:

Service Browser
This is the service browser, showing all the available services (service in this case : a custom php class holding functions for retrieving and adding database data )
Now click on the DiscoveryService (service which will give some information about all the other services, if available) , you will see that in the right box some items were added, those are the methods (like functions in programming). Clicking on one, and calling this method will result in some information in the bottom tabs…
If you do not see the newly added methods, proceed to the troubleshooting area …
Troubleshooting
Not getting as descibed above or getting error messages : one common mistake that many make, is forgetting to set the right file permissions … in FileZilla this can be easy done by clicking the amfphp base folder and right clicking – File Attributes … – set the parameters as folowing:

File Attribute Parameters
Just starting with playing around with the amfphp? register here for some nice , free webspace to get started …
Flash Remoting for PHP – Part 2 – Creating my own Service (getting data)
Coming Soon : Flash Remoting for PHP – Part 3 – Creating my own Service (adding data)
Coming Soon : Flash Remoting for PHP – Part 4 - Services & Flash Actionscript
Comments (2)
Comments (2)