postheadericon PHP PDO : insert, update delete example for beginners




Creating a web application using PHP (Hyper Text Preprocessor) and PDO (PHP Data Object). Here in this article I am exploring the latest feature of PHP to do better deal with databases. Yes, it’s PDO. After the many feature of MySQL function are improved or depreciated the MySQLi (MySQL improved) introduce. Still MySQLi is doing well but problem is you can connect to only one database using it that is MySQL. To improvise the better database connectivity option for most popular web server side scripting language PHP. PHP introduce PHP data object (PDO). So, Question is -, 

What is this PDO?

PDO is PHP data object which provide the data access layer. PDO have uniform and most powerful API methods to access multiple web databases using PHP.



PDO have many benefit as compare to MySQL and MySQLi. 


  1. PDO can connect 12+ popular database product.
  2. It have all the feature of MySQL functions.
  3. It is free from SQL injection.
  4. It is safe and robust.
  5. It is fast in execution.
  6. It is portable. No need to rewrite code on database product change
  7. It provide extreme use of Object Oriented Programming (OOP).
  8. It support database transections in PHP.

Let’s Experience the power and beauty of PDO using a simple example.

I have targeted this example to PHP and PDO beginners. In this example I am going to explore a web application which do insert, update, delete, search and display operations using PDO in PHP on MySQL database. Here I have used the prepared statement to do insert, update, delete, search and display records in MySQL database. 

I have try to keep my code as simple as possible so even beginners can also understand the example. I have organized PHP code in such a way that can be the stat up of any new simple PHP project. I have try to keep separate HTML and PHP portion as much possible.   

This example is divided in multiple part.


Part-1: Configure and Setup the MySQL database connection using PDO.
Part-2: Create a MySQL Database and a table using PDO.
Part-3: Insert record using prepared statement in PDO.
Part-4: Display Records using prepared statement.
Part-5: Search records using AJAX and PDO in PHP.
Part-6: Update Record using prepared statement in PDO.
Part-7: Delete Record using prepared statement in PDO.





1 comments:

Unknown said...

Hi. Great code.
Is this example free from SQL injection?
Best

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.