PHP With MySQL: Beginners Guide - Kussin | Development Unit Macedonia

PHP With MySQL: Beginners Guide


MySQL : an open-source relational database management system (RDBMS)

13.01.2023 | Ilir Raufi | Blog, Development

MySQL is a freely available open source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).SQL is the most popular language for adding, accessing and managing content in a database. It is most noted for its quick processing, proven reliability, ease and flexibility of use. MySQL is an essential part of almost every open source PHP application.

Software Requirements for the Tutorial.

To set up the PHP development environment, we mainly need two software, a code editor and a web server package.

We will be using :

  1. PhpStorm as the code editor
  2. And XAMPP to set up your local web server.

How to Create a Database?

A database is defined as an organized collection of data that makes the data easy to access, manage and modify. Generally, databases use SQL (Structured Query Language) for data manipulation.

To create a database:

  1. Open XAMPP Control Panel and start the Apache server and MySQL service.
  2. Now, go to your browser and type localhost in the address bar, and then on the XAMPP dashboard, click on the phpmyadmin tab.
  3. Into the phpmyadmin section, click on new to create a new database. Here, name your database “my_database”.
  4. Now, create a table named “users” that you can use to register users:

Keep the “id” column as Auto Incremented by clicking the check box next to ‘AI’ since it will be the primary key.

How to Connect Webpage to the Database Using PHP?

To connect the webpage to the database, create another file in the code editor named “config.php” and write the following code:

<?php

    $servername = “localhost”;

    $username = “root”;

    $password = “”;

    $dbname = “my_database”; 

    $conn = new mysqli($servername, $username, $password, $dbname);

    if($conn->connect_error) {

        die(“Connection Failed” . $conn->connect_error);

    }

?>

In this, you have learned how to create a database using XAMPP and MySQL. In the later sections, you learned how to connect the webpage to the database and then finally how to edit and delete the entries in the table using the phpmyadmin panel.

You can refer here for a video tutorial on the same.

Error: Contact form not found.