Update Data in Tables using PDO

How to update data in database tables using PHP PDO?


UPDATE query is used to update the vaules of the table. Here exec() method is called to update the table.

Syntax :

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

Example :

$count = $dbh->exec("UPDATE user_details SET last_name='victor' WHERE id='3'");
echo $count."rows updated';

To update particular row SET is used to set and replace value to the particular column.
Result :

1 rows updated

In the above example the last_name of id='3' is updated like 'victor' instead of 'rose'. The $count variable will display the number of updated rows.

PHP Topics

Ask Questions

Ask Question