Php and mysql connectivity

In this article, we will see how we can display the records by fetching them from the MySQL database using PHP.

Bạn đang xem: Php and mysql connectivity

Approach: Make sure you have a XAMPP server or WAMP server installed on your machine. In this article, we will be using the XAMPP server.

XAMPP is a free and open-source cross-platform web hệ thống solution stack package developed by Apache which allows a web application to lớn be easily tested on a local web server. Here, we can manually create a relational database và store data in tabular size by going to lớn this link. But lớn operate on localhost or for storing data first we have to lớn start Apache & MySQL from the XAMPP control panel. Let, for example, the database name is server, the table name is user_info having column name as ID, First Name, Username & Password và we have lớn fetch the data stored there. So, below is the PHP program whose task is khổng lồ fetch data.


Follow the steps khổng lồ fetch data from the Database using PHP:

1. Create Database: Create a database using PHPMyAdmin, the database is named “obatambeienwasirherbal.com” here. You can give any name to lớn your database.

Xem thêm: Người Yêu Giận Không Liên Lạc Với Mình, Đang Rất Hoang Mang, Chia Sẻ Mình Với,


create database “obatambeienwasirherbal.com”


2. Create Table: Create a table named ‘user_info’. The table contains four fields:

id – int(11) – primary key – tự động hóa incrementfirst_name – varchar(100)last_name – varchar(100)gfg_username – varchar(100)

Your table structure should look lượt thích this:


the table structure of “user_info”


Or you can create a table by copying và pasting the following code into the SQL panel of your PHPMyAdmin.

CREATE TABLE IF NOT EXISTS `user_info` (`id` int(11) NOT NULL AUTO_INCREMENT,`first_name` varchar(100) NOT NULL,`last_name` varchar(100) NOT NULL,`gfg_username` varchar(100) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM default CHARSET=latin1;To do this from the SQL panel refer to the following screenshot:


create a table ‘user_info” from the SQL panel


Insert records: We will now insert some records into our table. Here we are inserting 4 records. You can địa chỉ cửa hàng multiple records.


records in our table


Copy and paste the following code into the SQL panel to insert records into the table.

INSERT INTO `user_info` (`first_name`, `last_name`, `gfg_username`) VALUES ("Rohit", "Kumar", "rohitk987"), ("Nisha", "Jadhav", "nishajadhav001"), ("Aayush", "Joshi", "geeky1aayush"), ("Shweta", "Pawar", "shwetap12gfg");
inserting records


Creating folder and files:

We will now create our project thư mục named “obatambeienwasirherbal.com”. Create index.php and database.php files. Keep your main project folder (for example here.. obatambeienwasirherbal.com) in the “C://xampp/htdocs/”, if you are using XAMPP or “C://wamp64/www/” thư mục if you are using the WAMP hệ thống respectively. The thư mục structure should look lượt thích this: