php crud operation using pdo extension

php crud operation using pdo extension

In this article, We will create a PHP crud operation using PDO extension. The CRUD means Create, edit, update and delete. so here we will give you a simple example of insert, update, delete using PHP PDO with MySQL.

PDO stands for PHP Data Objects. PDO is a simple and consistent way to access databases. This means that developers can write portable code much more easily. PDO is not an abstraction layer like PearDB. PDO is just more like a data access layer that uses a unified API.

So you can see our example for PHP crud operation using PDO extension.

Create Database and Tables

connect to database in mysql

Create a  new connect.php file. The code below is to provide how to connect PDO with MySQL.
The following code is used to connect MySQL from PHP. It requires hostname, database username, database password, and database name.

Creating New Record in MySQL Database

Create a PHP file add.php in this file in add the below code.
The code below in the INSERT query through creates a new record to the database table. This HTML form contains input fields to enter user data to be inserted into the table.

PHP MySQL Read

Create a new PHP file index.php in this file in add the below code.
The following code shows how to fetch all the records from the database in the index file.

Php MySQL Update Record

Create a new edit.php file in this file to add the below code.
First, we will fetch a particular data record in the update form. On submitting edited user information we form an update query to edit the record with the reference of its edit_id.

Delete Record from MySQL Database

Create a new delete.php file in this file to add the below code.
The below code is used to delete a particular record from the database.

We think would you like this article, so you can click on “Show Demo” button and you can see this demo article.

Show Demo

Download

Please follow and like us: