VOOZH about

URL: https://www.geeksforgeeks.org/php/how-to-retrieve-data-from-mysql-database-using-php/

⇱ How to retrieve data from MySQL database using PHP ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to retrieve data from MySQL database using PHP ?

Last Updated : 23 Jul, 2025

There are steps to understand for retrieving the data from the MySQL database

Approach:

Now we understand each and every step as shown below.

 Example 1: In this. we use PHPMyAdmin for the database handling. Start the server in the XAMPP as shown in the below image

Making sure that both Apache and MySQL are showing green color, means that the server is working.

👁 Image
XAMPP PANEL

After that create the database in the PHPMyAdmin. Open the below URL.

http://localhost/phpmyadmin/index.php

Creating the database:

👁 Image
creating the database in MySQL PHPMyAdmin

Create the table: Execute the SQL query in the "gfg" database.

CREATE TABLE student
( 
 name varchar(20), 
 branch varchar(20),
 roll_no INT
);

Enter the data in the table.

INSERT INTO `student` ( `name`, `branch`, `roll_no`) 
 VALUES ( 'Rohan', 'CSE', '1' );

After the data is inserted, the table will look like this.

👁 Image
After entering the data in the table

PHP Code: Run the PHP script as shown below to fetch the data from the database.

Output:

👁 Image
Output of the above PHP script
Comment