CRUD Operation in PHP-PDO - Web Development

CRUD Operation in PHP-PDO

Today i am giving you toturial on PDO-PHP .Here i will creat full CRUD system in PDO using PHP. So below is your connection in PDO so see carefully it looks tought but dont worry it is very easy compare to Mysqli. I didnt give file name here it is upto you what name you want to give. Just remember the syntax ”bindparam” is used for bind your data and colon ( : ) is uesd for SQL INJECTION prevention

Always use try & catch block for pdo connection and if you dont use try-catch then you cant cathc your error . For source code comment your mail

I have used PHP include_once function to connect database connection to all files but you can write DB connection in each file but good practise is use connection file separately and connect it with help of require_once or inlcude_once.

Now this is screen short of your add form page

Now this is your form code

This code will use for insert your data in table using PDO Method

Now i am putting code of index file ,Below is your index.php file or you can say main page of your small project

We can use query or execute statement method in PDO but exceute is more safer than query against Sql Injection

query runs a standard SQL statement and requires you to properly escape all data to avoid SQL Injections and other issues.

execute runs a prepared statement which allows you to bind parameters to avoid the need to escape or quote the parameters. execute will also perform better if you are repeating a query multiple times. Example of prepared statements:


So i have given you two examples how to write query and excecute method in PDO

This is screenshort of your index.php

Now i will put code of edit.php

Now this is final code block which your delete.php

This way you can do CRUD Operation in PHP-PDO.

Check these tutorials in php

Leave a Reply

Your email address will not be published. Required fields are marked *