Demonstration of CRUD operation with PDO database connection

 Databases are everywhere and there is no practical PHP application that could exist without a database. From the very beginning, PHP offers several ways of interfacing with all popular DBMS. For instance, two popular ways of interfacing with MYSQL database are mysql and mysqli.

Over years, databases have come a long way and now several different vendors offer popular DBMS that power modern PHP apps. To standardize and streamline development practices, PHP introduced PHP Data Objects (PDO) in PHP 5.1. These objects are used to setup PDO database connections.

PDO is a database access layer which provides a fast and consistent interface for accessing and managing databases in PHP applications.  Every DBMS has specific PDO driver(s) that must be installed when you are using PDO in PHP applications.

 

Follow the given steps :

STEP 1 : Establish a connection with Database  

 Create a new file name as connection.php in project directory /var/www/html 

 now for establishing connection write a php program in connection.php file given below 

STEP 2 : CREATE  A TABLE IN DATABASE 

Create a file as create.php to create a database table as given 



STEP 3 : INSERT DATA IN TABLE 

 Create a php file name as insert.php to insert data in created database in program as given below 




STEP 4 : UPDATE DATA IN TABLE 

create a php fiile name as update data in created table through the program given below 


 STEP 5 : DELETE DATA IN TABLE 

Create a php file name as delete to delete data in the table by the program given below 



CONCLUSION :  

PDO is the data accessing layer that greatly eases the process of connecting and working with databases. Perhaps, the best thing about PDO is the streamlined process of database migration.

In this article, I introduced PDO and highlighted how you could perform CRUD actions using PDO in PHP. I also demonstrated setting up of PDO database connections. If you have questions or would like to add to the discussion, do leave a comment below.

Comments