The UPDATE order alters existing fields by evolving values. It utilizes the SET provision to indicate segments for alteration, and to determine the new qualities appointed. These qualities can be either an articulation or the default estimation of the field. Setting a default esteem requires utilizing the DEFAULT catchphrase. The order can likewise utilize a WHERE statement to determine conditions for an update as well as an ORDER BY provision to refresh in a specific request.
Survey the accompanying general punctuation −
UPDATE table_name SET field=new_value, field2=new_value2,...
[WHERE ...]
Execute an UPDATE order from either the order brief or utilizing a PHP content.
The Command Prompt
At the order brief, essentially utilize a standard commandroot −
root@host# mysql -u root -p password;
Enter password:*******
mysql> use PRODUCTS;
Database changed
mysql> UPDATE products_tbl
SET nomenclature = 'Fiber Blaster 300Z' WHERE ID_number = 112;
mysql> SELECT * from products_tbl WHERE ID_number='112';
+-------------+---------------------+----------------------+
| ID_number | Nomenclature | product_manufacturer |
+-------------+---------------------+----------------------+
| 112 | Fiber Blaster 300Z | XYZ Corp |
+-------------+---------------------+----------------------+
PHP Update Query Script
Utilize the mysql_query() work in UPDATE order articulations −
<?php
$dbhost = ‘localhost:3036’;
$dbuser = ‘root’;
$dbpass = ‘rootpassword’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die(‘Could not connect: ‘ . mysql_error());
}
$sql = ‘UPDATE products_tbl
SET product_name = ”Fiber Blaster 300z”
WHERE product_id = 112’;
mysql_select_db(‘PRODUCTS’);
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die(‘Could not update data: ‘ . mysql_error());
}
echo “Updated data successfully\n”;
mysql_close($conn);
?>
On fruitful information update, you will see the accompanying yield −
mysql> Updated data successfully