MySQL tutorial delete data SQL statement usage
The delete from statement is used to delete records from a database table.
Grammar
DELETE from table_name WHERE COLUMN_NAME = some_value
Note: SQL is not sensitive to case. Delete from is equivalent to delete from.
In order for PHP to execute the above statement, we must use the mysql_query (function). This function is used to send queries and commands to a SQL connection.
Example
Earlier, we created a table named "Person" in this tutorial. It looks something like this:
FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33
The following example deletes all lastname= ' Griffin ' records in the "Person" table:
$con = mysql_connect ("localhost", "Peter", "abc123");
if (! $con)
{
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("my_db", $con);
mysql_query ("DELETE from the person WHERE lastname= ' Griffin '");
Mysql_close ($con);
?>
After this deletion, the table is like this:
FirstName LastName Age
Peter Griffin 35
Note : More wonderful articles please pay attention to the triple programming Tutorial column.