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 Control Panel. Then click the "My SQL" icon (Sotware/Services -> MySQL).
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:
-database = a3734759_db ["a3734759_" part will be different in your account]
-user = a3734759_user
-password = pwd1234
(REMEMBER THIS DATA FOR THE PHP PART)
Congratulations, you have created your first database!
Databases are a collection of data organized in tables. Every table saves data about scomething, 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...
Creating a database table
Go back to your Control Panel and select phpMyAdmin. Then click Enter phpMyAdmin
A new window of phpMyAdmin 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 and 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...
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: "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...