PHP MySQL Delete
Posted by tutor | Posted in About Websites, PHP Tutorial | Posted on 04-07-2010-05-2008
0
You can delete records by using the DELETE statement.
Syntax
- DELETE FROM table_name
WHERE some_column = some_value
Again we used WHERE clause here in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted.
For eg:
Country Capital
Zimbabwe Harare
Poland Warsaw
<?php
$conn = mysql_connect(“localhost”,”tutor”,”tutor123″);
if (!$conn)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“my_db”, $conn);
mysql_query(“DELETE FROM Country WHERE Capital=’Warsaw’”);
mysql_close($conn);
?>
$conn = mysql_connect(“localhost”,”tutor”,”tutor123″);
if (!$conn)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“my_db”, $conn);
mysql_query(“DELETE FROM Country WHERE Capital=’Warsaw’”);
mysql_close($conn);
?>
After the deletion, the table will look like this:
| Country | Capital |
| Zimbabwe | Harare |
