For this Tutorial you will have to have some basic knowledge of PHP and mySQL, hopefully you won't need much though. It is also assumed that you have a good understanding of Flash Actionscript. What this tutorial basically does is to show you how to set up a table in a mySQL database, then using PHP (or asp with a few minor changes) manipulate that table and interact with Flash. The first part of the Tutorial shows you how to create a unique user ID in the database, In this case it will be the persons name. With a few minor changes however you'll be able to make it a secure password protected user login. The unique user ID is required because in the next part we'll be saving the position of a couple movie clips and some of their property's. In this way a user can return to the (your) site at anytime and the movie Clips will be in the exact same position that they left them in. I also added in a place for the user to add in a comment, which is also saved. With a couple modifications you can turn that into a guest book or anything else you can think of. This is a much more of a hands on tutorial so it's helpful if you follow the scripts and Fla source included, in addition to viewing the working example at the same time.
It is recommended that you read over the PHP scripts first. These have all been extensively commented. In PHP the # symbol is a comment. Also it may be best to try to follow the code in the included Flash movie along as well.
You must have a mySQL server set up by your host or on your local machine. I'll be using the most basic shell commands to set up the table. However their are GUI's out there to make this part easier. Your host may already have one set up for you to use. Make sure to read all the documentation your host has available on using mySQL on their servers - some may be different. But it should all basically be the same.
Once your database has been set up. Open up your shell account. In most cases you can use Telnet to get to your account. From the telnet command prompt - type in
mysql -p YourDatabaseName Then you will be prompted for a password. Type in your password. You'll see some text appear after this, then the command prompt changes to read
mysql> (then Type)
use Database Name. We will name the table
saveMovie for this example. Then type in the following create table syntax exactly as it appears below:
You can then use the
describe table command to see what the table looks like.
Here are a couple other mySQL commands you may find useful from the shell.
Change the Column Name: mysql>
alter table saveMovie change Name SomeotherName varchar(30); (This just changes the name notice the syntax - after change enter the old Column Name followed directly after by the New column name and definition.
Delete one of the Columns: mysql>
alter table saveMovie drop Name; This just deletes the column that you had previously named "Name".
Select and view everything in the Table: mysql>
Select * from TableName;
Delete the whole table and start over: mysql>
drop saveMovie;
Short List of Column types (note if the data that you have entered into one of these definitions is larger then the amount you specified in the table it will be cut off):
varchar (Number) - A variable text type - in my opinion the easiest and most flexible to use when first starting out. Maximum is 60 characters Long.
char (number) - A fixed character type column.
int (number) - A fixed integer type column. Default is 14 if you leave it blank.
text or blob - use either when you want to enter a large amount of text.