What is MySQL and PHP

MySQL

Hand-bound notebooks

Health reasons force - and bring (!) - me to changes that were never planned: Instead of variables, loops and queries, I now work with wonderful paper: wafer-thin tracing paper, matt white writing paper, rustic kraft paper, flexible, black cardboard, solid Gray board and many more. All of them are used to create hand-bound notebooks, diaries and notebooks that are fun to look at - just imagine how great it is to write in them too!

PHP for you will of course remain in its current form and maybe we'll see each other at Unkelbach Art, on Facebook or Instagram or you can get one of my products. It would be my great pleasure!
More on this...

Connection to the database ...

... take up.

In order to be able to access the data in our database with PHP, we first have to establish a connection. This is done using the command mysqli_connect and before all other contents of the document.

The command requires the server name, username, password and the desired database. It is also possible to specify the port and socket, but in most cases this will not be necessary for you.

The username and password are each provided with the database. You can either find it in the configuration interface of your host or you may have received it by email. The server name is often "localhost". More and more hosters have outsourced their databases to their own server. In this case, the path to the server must be specified. The name of the database is usually also given by the hoster and can be found in most cases where you create your database.

In order to be able to address the database connection (and thus the database itself) later, we write the connection establishment in a variable. So it looks like For example: If something does not work when connecting to the database, it makes sense to display error messages so you know where the error occurred. It looks like this: After the connection to the database it is checked whether something is actually in our variable $ db is included. If not, something has gone wrong and we call the function exit on. It ensures that the following code is not executed and also shows what we have specified in the brackets after it. In our case the text "Connection error:" followed by the command mysqli_connect_error (). This contains the error message that mySQL returned and will hopefully help us solve the problem.

Sometimes you will be over the command the instead of exit bump. It works the same way and usage is just a matter of personal preference.

Since the data for the database connection is in most cases used in several files, but could change if the server is relocated, it makes sense to save this part in a separate file and then use the command include to be included in every page - so you only need to make a later change in one file.

For me, this file is called dbconnect.php (the ending doesn't matter, but a PHP file cannot be read by anyone and therefore the data is safe) and contains exactly what we have already done above: in the file in which we set the database connection need is then at the top (in front or anything else) Next, let's look at how we can query our data.

This chapter provides a first introduction to working with mySQL databases. It provides a basic understanding of the communication between PHP and the database. For productive use, it makes sense to deal with this topic in more detail and pay special attention to security aspects.