There might be a prerequisite where existing information in a MySQLi table should be adjusted. You can do as such by utilizing SQL UPDATE order. This will alter any field estimation of any MySQLi table.
Syntax
Here is nonexclusive SQL language structure of UPDATE order to adjust information into MySQLi table −
UPDATE table_name SET field1 = new-value1, field2 = new-value2 [WHERE Clause]
- You can refresh at least one field inside and out.
- You can indicate any condition utilizing WHERE provision.
- You can refresh values in a solitary table at a time.
The WHERE provision is valuable when you need to refresh chosen columns in a table.
Updating Data from Command Prompt
This will utilize SQL UPDATE order with WHERE statement to refresh chosen information into MySQLi table tutorials_inf.
Example
Following model will refresh name field for a record having tutorial_inf.
root@host# mysql -u root -p password;
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> UPDATE tutorials_inf
-> SET name = 'johar'
-> WHERE name = 'sai';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
Updating Data Using PHP Script
You can utilize SQL UPDATE order with or without WHERE CLAUSE into PHP work mysqli_query(). This capacity will execute SQL order in comparative manner it is executed at mysql> brief.
Example
Evaluate the accompanying guide to refresh name field for a record.
<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$dbname = 'TUTORIALS';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
if(! $conn ) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully<br>';
$sql = ' UPDATE tutorials_inf SET name="althamas" WHERE name="ram"';
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
The example yield ought to be this way −
Connected successfully
Record updated successfully