Creating a Database (MySQL)
We are going to create a database. A database is an organized collection of data. This is very helpful to store highscores, usernames and many other information useful in your games. MySQL is a powerful language to create and manage databases.
Log in to your account, access your Dashboard ("Manage Website"). In Tools go to Database Manager and create a New Database.
In the new window, you will create a database: with a database user and a database password. You can fill this data as you want, but I recommend you to copy the same info as shown here (so you can follow better the tutorial then you can change it later):
-database = db
-user = user
-password = ******** (whatever you want but don't forget it. You'll need this in a few minutes)
Notice that your complete database name is not 'db', it is something like id13353839_db. Also, your username is not 'user', it's again id13353839_user.
Congratulations, you have created your first database!
Creating a Database Table
Databases are a collection of data organized in tables. Every table saves data about something, like data about "users", data about "scores", data about "friends", etc...
Our recently created database is right now empty, we have to create our first table. Let's see how to create a table...
Go back to your Control Panel and enter phpMyAdmin.
A new phpMyAdmin window will open up. We can see that there are no tables created yet. But we are about to add the first one.
Click the tab called SQL to write SQL code. Paste the following code and click "GO":
CREATE TABLE `scores` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 20 ) NOT NULL ,
`score` INT NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = InnoDB;
Now a new table has been created. This code tells MySQL to create a table with three values: ID, NAME and SCORE. So for every user sending a score to the database, we will store his name and his score.
Notice how on the left side now we have a table: 'scores'. We can also see the structure of this table...
Great!
We have now our table ready so we can start writing and reading scores from PHP files!
(Manually) Inserting your first row
Tables are composed by 'rows'. Every row has information about the same subject. In the 'scores' table, every row must contain 3 fields: id, name and score.
For example one row is (ignore id): "JohnSmith 815"
We are going to manually add a row for testing purposes. Click the Insert tab and add the following information to the new row, then click the "Go" button:
If you click the Browse tab you can see all the information stored in this table. In other words: you can read all the scores submitted !!!
We have manually added some data to our table. Now we will see how to write and read scores from PHP files. Read on...