Insert Data MySQL Database Using PHP PDO Method

In this tutorial how to insert data in a MySQL table using PDO Method in PHP

MySQL INSERT Query using PDO Method

We will discuss PHP PDO Method. Example is given below.

This new PDO() function is establish database connection. Next set POD error mode. $e variable show database connecting error. INSERT INTO sql query insert data Mysql database table. $pdo->exec($sql) function executed INSERT INTO sql query. Then close connection.

Database Structure example is given below

database table structure
database table structure

PDO Handle Errors

The three type error modes manage the error mode attribute in your newly created database connection.


Example is given below

Three methods are writing in the INSERT INTO statement. Procedural Method and Object Oriented Method as we discussed earlier.

Saurav Sen

Saurav Sen

Hi, I am a professional blogger and web developer. So I also share experiences with web development tutorials and blogging tips and including writing about HTML, CSS, JavaScript, Jquery, Ajax, PHP, and MySQL.