How to create database in PhpMyAdmin?

Shital MainaliShital Mainali
3 min read

Creating a database

PHPmyadmin is a popular web-based tool for managing MySQL databases. With PHPmyadmin, you can create, edit, and delete databases, tables, and records. In this tutorial, we will guide you through the process of creating a database 'test' in PHPmyadmin with a table name 'data' and attributes id, name, phone, email, and message.

  1. Step 1: Open PHPmyadmin

    The first step is to open PHPmyadmin in your web browser. If you have already installed PHPmyadmin, you can access it by entering the URL http://localhost/phpmyadmin/ in your web browser's address bar.

  2. Step 2: Create the 'test' database

    Once you have opened PHPmyadmin, click on the 'Databases' tab. In the 'Create database' field, enter 'test' as the database name and click on the 'Create' button. This will create a new database named 'test'.

  3. Step 3: Select the 'test' database

    After the 'test' database is created, click on the database name to select it. This will display a list of all the tables in the 'test' database.

  4. Step 4: Create the 'data' table

    To create a new table, click on the 'SQL' tab to open the SQL query editor. In the SQL query editor, paste the following code:

     CREATE TABLE data (
       id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
       name VARCHAR(50) NOT NULL,
       phone VARCHAR(30) NOT NULL,
       email VARCHAR(50) NOT NULL,
       message VARCHAR(255) NOT NULL
     );
    

    This SQL code creates a table named 'data' with attributes id, name, phone, email, and message. The 'id' attribute is set to auto-increment and is also the primary key.

  5. Step 5: Run the SQL Query

    After pasting the SQL code, click on the 'Go' button to run the SQL query. This will create the 'data' table in the 'test' database.

Step 6: Verify the 'data' table

To verify that the 'data' table has been created, click on the 'Structure' tab. This will display a list of all the tables in the 'test' database. The 'data' table should be listed with the attributes id, name, phone, email, and message.

Creating a database 'test' in PHPmyadmin with a table name 'data' and attributes id, name, phone, email, and the message is a simple process. You just need to open PHPmyadmin, create the 'test' database, select the 'test' database, create the 'data' table using SQL queries, and verify the 'data' table. With this knowledge, you can start building your databases and tables in phpmyadmin.


Bonus:

Executing 'select' query using PHP

To see how to include a database connection file Click here

include 'database.php'; //Including database connection file
$sql = "SELECT * FROM data";
$result = $mysqli->query($sql);

// Check if there's an error in the query
if (!$result) {
  echo "Failed to retrieve data: " . $mysqli->error;
  exit();
}

// Display the data in a table format
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Phone</th><th>Email</th><th>Message</th></tr>";
while ($row = $result->fetch_assoc()) {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['phone'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['message'] . "</td>";
  echo "</tr>";
}
echo "</table>";

On the next blog, we will learn how to execute all query using PHP.

0
Subscribe to my newsletter

Read articles from Shital Mainali directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shital Mainali
Shital Mainali

Well, hello there! I'm what you might call an enthusiastically frustrated developer. You see, I have a love-hate relationship with coding. On the one hand, I can't get enough of it - I get all giddy at the thought of creating something new and exciting. On the other hand, it's like trying to solve a Rubik's cube blindfolded while standing on one foot. It's frustrating, it's maddening, and it's just a little bit hilarious. But hey, that's the life of a developer! I'm always up for a challenge, and I'm constantly trying to improve my skills. So, if you need someone to code you a website or an app, just know that I'll be over here banging my head against the keyboard until something magical happens. Cheers to the joys and frustrations of coding!