Insert Data into Table using PDO

How to insert data into a table using PDO?

Explanation

INSERT command is used to insert values into the table. This statement is used to add new records into the table.

Syntax :

$qry->exec("INSERT INTO tablename(columns) VALUES ('')");

Example :

$qry->exec("INSERT INTO user_details('first_name','last_name','email') VALUES ('John','paul','john@gmail.com')");

In the above example, 1 row is inserted with the values like 'first_name=John','last_name=paul' and 'email=john@gmail.com'. The column is set to be an auto_increment one, so there is no need to insert id column.
The output for the following query will be like,
Result :
pdo-insert

To retrieve/display the inserted values, "SELECT" query is used. It will be explained in the next chapter.

PHP Topics


Ask Questions

Ask Question