1. Layout of a mysql database
Whatever a php script is doing soon or later the php script must save the data somewhere. All variables are deleted after the script ends and are removed from the memory. It is possible to save these data in a file. The php script opens the file and reads or write to it as an user would edit an text file. If your create a guestbook with files as storage you can save it like this:
User|20. Jan 2008|Really good page User2|11. Feb 2008|Hi Paul, how are you? User3|13. Feb 2008|Cool page, visit my homepage too
Each row will be a guestbook entry and the character |
is the delimiter for usernames, creation date and the text.
The php script reads this file and use explode to
get the three parts back.
For a relational database like MySQL a different approach is taken. The data are not saved in files but in tables. Each row in the table represents an entry. MySQL is using the following layout.
-
First there exists the MySQL programm itself, its an application like everything else. It implements a login system to access the database.
-
Inside this MySQL program are the databases. These are the workspaces for the users which logged into MySQL. Depending on the login only a subset of databases can be used. Typically each user have his own database. A costumer like
usr_123456got a databaseusr_123456to use. -
Inside one database are the tables, which can be added, changed or deleted. At the beginning this area is empty and the user must create the tables. This can be done with a administration programm or application like phpMyAdmin. This is a common webinterface for working with MySQL databases. Each table got a list of columnnames and types and some additional objects like primary key or indexes.
-
Inside the tables are the rows. Each row combine one column of the table with a value. As an example a row combines the column
Usernamewith the valueFoobarand the columnBirthdaywith the value1.1.1980. A second row will assign the valuesUserBarand2.4.1975to these columns, but both rows are in the same table. This will look like this.Example of the table Username Birthday Foobar 1.1.1980 UserBar 2.4.1975
To you a MySQL database in php you need 4 values. You get them from the administrator of your webserver.
-
Host - This is the address to the server where mysql is installed. It can be any IP or host like
db23.example.combut is often the same computer as the webserver is running. In this case the host islocalhost -
Username - The username to login.
-
Password - The password to login.
-
Database - The database to work with. A webapplication always use only one database.