In the event that you need to erase a record from any MySQLi table, at that point you can utilize SQL order DELETE FROM. You can utilize this order at mysql> expeditious just as in any content like PHP.
Syntax
Here is nonexclusive SQL sentence structure of DELETE order to erase information from a MySQLi table −
DELETE FROM table_name [WHERE Clause]
- On the off chance that WHERE proviso isn't indicated, at that point all the records will be erased from the given MySQLi table.
- You can indicate any condition utilizing WHERE provision.
- You can erase records in a solitary table at a time.
The WHERE provision is helpful when you need to erase chosen lines in a table.
Deleting Data from Command Prompt
This will utilize SQL DELETE order with WHERE statement to erase chosen information into MySQLi table tutorials_inf.
Example
Following model will erase a record into tutorial_inf whose name is johar.
root@host# mysql -u root -p password;
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> DELETE FROM tutorials_inf where name = 'johar';
Query OK, 1 row affected (0.23 sec)
mysql>
Deleting Data Using PHP Script
You can utilize SQL DELETE order with or without WHERE CLAUSE into PHP work mysqli_query(). This capacity will execute SQL order in comparable manner it is executed at mysql> brief.
Example
Evaluate the accompanying guide to erase a record from tutorial_inf whose name is althamas.
<?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 = ' DELETE FROM tutorials_inf WHERE name = "althamas"';
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
The example yield ought to be this way
Connected successfully
Record deleted successfully