Learnit Training

5. PHP and MySQL

5.1. Databases

If we want to save data (e.g. from Web Forms) we can do that in text files. And that goes well as long as it is not too much data and as long as we do not undertake complicated operations or searches through this data. As soon as we want to do that, it is clever to use a database system. The database allows for storage in files, there is nothing more to do with it. Furthermore, the database provides a system for disallowing searches on the data. This goes through SQL, (structured Query Language). We will deal with SQL in the next chapter, although there is something to be seen here as well.

5.2. MySQL

MySQL is such a database system, we use this system because:

  • The open source (and therefore free) is
  • Despite being free, a very comprehensive and stable database server is
  • The most used database in combination with PHP is
  • Already installed on your computer if you have XAMPP installed
Enough reasons, but it is also possible other database systems as Microsoft Access, Postgress Or SQL Server To use.

5.3. PhpMyAdmin

A database is a system that takes care of storing, editing and querying data. And that's actually all it is. There is nothing to see. If you have opened Microsoft Access , you will know that there is something to see (Tables, queries, forms, etc). Although this is often called the database , it is in Fact a DBMS (Database Management System) that you see. A DBMS is the interface for a user to the underlying database. For MySQL We also need such an interface, there are several, but again we choose the most used and most user-friendly variant that is already installed on your computer if you have XAMP installed. This DBMS is called PhpMyAdmin.

PhpMyAdmin can be found, if it is installed, on http://localhost/phpmyadmin/. In this case, the DBMS is not secure (you don't need to log in), because we only work on your own computer. In PhpMyAdmin We can edit the databases. We can create new databases, add tables, change tables, delete them, query the databases and even more. For more information, please visit the website of The PhpMyAdmin Project .

5.4. A database

It goes too far to elaborate on how databases work exactly. You can follow us a training MySQL Administering . What we do is create a database that can store the reactions from our form. It becomes a database that is called comments with two tables:


Note: The above image has been CREATED with MS Acces because PhpMyAdmin does not have such a view. It is only meant as illustration!

What we see is a database (the whole) that is called comments . Two so-called tables that people and reactions are called. Both tables in turn have so-called attributes. There is also a one-to-many relationship between individuals and reactions, which means that one person can make multiple reactions. Another important aspect is that both tables have an attribute Id . This ensures that a record that eventually appears in the table is uniquely identifiable (it is possible that a person sends the same message twice, they want to be able to keep them apart).

You can try to create the above database by using PhpMyAdmin. You can also just Create. txt Copy the contents to the Clipboard, to http://localhost/phpmyadmin/ Surf and left on the button SQL (SqlClicking. A so-called Query window Where you can paste the contents of the Clipboard. Op Go (or Start Depending on your version) press will cause the database to create comments! In the next chapter we will continue with this.