PHP & MySQL Basics: Databases & Tables

To test MySQL with PHP on your own computer, you need a separate server. You can setup your own server on your PC by Installing XAMPP or XAMPP lite and you can run PHP scripts on your computer and use PHPMyAdmin to create databases, run SQL, etc.

Start server, create database

After you have installed your server, you have to start it. Then enter in the browser of your choice, following the URL: http://localhost/xampp/. This takes you to the XAMPP start page and in the left menu under Tools, check the link phpMyAdmin. Search now in the whole huddle, the text Create new database. Below is an input field into which you write the name of your database. Let us take the names easy tutorial, the Collation box you can ignore for now.

The next steps

Congratulations, you have created your first own database. But that was just the beginning. In the following parts, you will in your database to create tables , enter values and advance with SQL play around a bit. Then go directly to MySQL. We are producing with PHP connect to our database and the main operations of MySQL Meet ( SELECT , INSERT , UPDATE , etc).

Create table

The next step is made immediately after the database has been created. Under the text Create new table … there is an input field, in which we enter the name of our table. When names of tables, columns, etc., we have to be a free hand, as long as we do not use the reserved words of MySQL: Reserved Words in MySQL . In PHPMyAdmin, you can use reserved words without an error message, but I h3ly advise against this because it is a pre-programmed error source. Anyway, we want our first table name in our database customer. So Give customers as table name and “number of fields” the value of 2. The two fields must now be filled correctly in the following form, only then will our table be generated.

MySQL Create Columns

Each table can have any number from at least one to any number of columns. The columns are our types, so if we want to have a table in which only names are stored, then we need only one column with the label name and can enter in any number of names. Or we have a table appointments, in which we the time of the appointment Enter (column name “datum”), a description of the event (column name “description”) and the place where the appointment takes place (column name “village”). Depending on how many values we want to keep in the table, the number of columns required is increased.

Fill out the table form

Both columns are of type VARCHAR that is, the columns expect strings as input. Entering Length/Values depends on the type. For VARCHAR there a value must be entered and that a number between 1 and 255. The number indicates how long the respective string may be respectively. The name of our customers can not be longer than 60 characters, the address must not exceed 100 characters. The remaining values you can ignore.