First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Jeffrey F. Hill | Website: http://www.flash-db.com

Using PHPMyAdmin and a Simple Example of creating a Flash Database app

The following exercise's work through creating a table, using PHP to access that table and building a Flash Client For the User Interface.

First Create a New Database: In the Text field just beneath 'Create a new database' on the main page enter FlashTest.  Then click 'Create'.  You should get a message such as 'Database FlashTest has been created'.  

Note: Creating a database will create a Folder in the C:\mysql\data directory.  You can check to see if the folder 'FlashTest' is their - it will be.  A database is made up of individual Tables, you can have as many tables in a database as you want.  Each time you create a Table in your database it will create 3 new files in your C:\mysql\data\FlashTest\ folder.  You really don't need to know this info - but it might be interesting to know where your data is physically being stored - that's where.

Next where going to create a table. On the current screen find where it says "Create new table on database FlashTest" - then for the Name call it "news".  For the amount of Fields enter "4".

On the next screen you'll see something that looks like a table.  Fill it out as following by selecting items from the drop down menu, or typing them into the fields - only the columns that where using where included:

Field Type Value Extra (other)
ID INT   auto_increment Check primary key
UserName Varchar 30    
News Text      
TimeAdd Date      

That's all you'll need for our first table.  After you've entered that click 'Save'.  After that you should come to a new screen and the message "table News has been created" should be up top.  You've just created your first table with PHPMyAdmin!

Other items you can now do with your database:  First of all try to explore all of the options in PHPMyAdmin.  You can't really hurt anything at this point so just try everything.  When your looking at a new table you can click on 'Properties' which allows to change some of the Fields and Type's around.  You can also click on Insert - where you can manually enter new records if needed.  One Important part is a bit further down that page where it says something like "View dump (schema) of database" - using the options below that you can create a backup of your database.  If you dump the Structure of the database this will create some SQL (instructions) in formatted text - this SQL can be used to replicate/backup your database on any computer by instructing MySQL how to re-create your database exactly as it was at the old location.  For this example is we dumped the table structure of 'FlashTest it would look something like:
CREATE TABLE news (
  ID int(11) NOT NULL auto_increment,
  UserName varchar(30) NOT NULL default '',
  News text NOT NULL,
  TimeAdd date NOT NULL default '0000-00-00',
  PRIMARY KEY  (ID)
)

Now what can we do with this table.  Well first where going to write two scripts and a small flash movie so that we can work with this table we just created.  The two scripts consist of your 'Middle Layer' that act as a messenger between your flash client and the MySQL database you have just created.

Building the Flash Client:  (All example files come with the download).  Since this tutorial has already taken a while - the Actual Flash client was included in the download and will not be covered here in great detail.  The main parts to it consist of 1 text area called: News.  Where you News will be loaded to from the database.  And two other text fields called 'UserName' and 'EnterNews'. Their is also one button.  What this will do is just a small example of selecting and inserting data from/into a MySQL database.  On the 'Add News' button their is the following Actionscript: loadVariablesNum("AddNews.php","0","POST");  This handles adding/inserting a new record into the database.  Their is also one frame action that loads the current news from the database: loadVariablesNum("SelectNews.php","0");

You should be able to add the 'FlashExample' folder (in the download) to your htdocs web root folder and have everything working right away - as long as the above steps in creating your database and table where followed above. 

The AddNews.php script contained in the download will take a User Entered Name and a news Item and add it to your newly formed table (news) in the Database (FlashTest) - when the 'Add News' button is pressed.

The SelectNews.php script will Select all of the news Items currently in the table (news) in the database (FlashTest) we just created and display them in your Flash movie.

Their is also a refresh button on the Flash client that will allow you to refresh the News area after you've added a new entry.

And I think that's about it.  Hopefully that small sample is at least something you can follow along with the Code in the scripts and Flash movie.

» Level Advanced

Added: 2002-05-08
Rating: 9 Votes: 108
(10 being the highest)
» Author
Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content, applications, and content management systems. Specialty's include SQL, PHP, Perl, XML, web services, and Flash clients for web services.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.