Managing MySQL data with PHP and use them in a simple Flash MX application.
Hi to all! Welcome to this tutorial in which I'll try to guide you through the communication between Flash MX and a MySQL database with the help of a PHP script.All in this tutorial will be explained as simple as possible, to help everyone, even at a beginner level, to reach the goal.
Ok, let's begin our lesson. First of all we'll need a couple of tools to work: these are a web server (Apache recommended), PHP 4 or later and the MySQL database. Refer to the main page of this tutorial section to find the links for downloading these free tools. We need our web server and modules working on our machine, or at least on our remote website. To make them working, please refer to the documentation included with each software. I recommend the phpMyAdmin application too, as it helps us saving time and building our database easier.
2. Start Up
Well, once we have all the system ready we can start to prepare the base on which we will build our application. So open the phpMyAdmin main interface simply digiting an url similar to the following in the address bar of our browser: http://localhost/phpMyAdmin/
You are asked to login if your configuration settings require it. After logging in, you'll see the phpMyAdmin main page from where we will build a new database. Fill-in the "Create New Database" textbox and click on the Go button to generate the new database. In my example the database that I built is called simply "flash". Selecting the new database we will find the "Create new table" textbox. Let's write into it the name of the table that we will need for our project: in my example (picture 1.1) I called it "news". Click on the Go button and at last we have the "news" table in our "flash" database.
For our purpose, we need only one table, because our Flash News Display will only show the date and the corresponding piece of news. So let's give a structure to the "news" table. If you made all in the correct way, now you should see a form to fill. This is the structure form, where we can define the fields of the current table. You can reach this section later simply by clicking on the table name in the database list on the left frame and then selecting Edit on the upper table that shows all the fields of the selected table and their options. For the news table I made three fields:
- id, notizia (that in Italian means "piece of news") and data (that means "date").
For each one I selected a datatype, a tinyint for the id field (with the auto_increment option on), and varchar (with different lenght) for the other two fields. I didn't use a date datatype for the data field simply to avoid later conversions: in this way, we can fill it in with a custom date and we will see it in the same way in the output in our Flash movie. The id field is not indispensable, but every table should have its own id field, you can see its importance if you will work on DBRMs. We can also set this field as Primary key, Indexed and Unique. Now you should have a structure really similar to the one in picture 1.2.
So proceed you now and write something in the the table simply by clicking on "insert" under the table structure that we completed before. As you can notice in picture 1.3, I also used html tags in the last record. Why? Because in this way we can use also html-formatted text in our flash movie, adding a little more interactivity to our news (for example users can click on a link and reach the responding section in our website).
Well, ladies and gentlemen, we finished working with phpMyAdmin, now you will use it only when you will have some pieces of news to add.