PHP MySQL Delete query- Php Mysql Create Database - Phptpoint.com

PHP MySQL Delete

/ins>

PHP MySQL Delete

DELETE keyword is used basically to delete 1 or more than one records from the database table.even if we delete each and every row of a table then also the schema of the table remain un deleted. It,s necessary to use where clause in delete query, otherwise all the records will be deleted.

Syntax

Note : Notice the WHERE clause in the DELETE syntax is must otherwise all records will be deleted!

Eg 1

Previous records in empInfo table are:

Emp_id Name Email Mobile
1 devesh devesh@gmail.com 9910099100
2 deepak deepak@gmail.com 9210053520
3 ravi ravi@gmail.com 9810098100

 

This example deleted one row from “empInfo” table

After deletion , the “empInfo” table will look like this:

Emp_id Name Email Mobile
2 deepak deepak@gmail.com 9210053520
3 ravi ravi@gmail.com 9810098100

In the above example ,
empInfo table has 3 records of devesh,deepak, and ravi.
we need to delete a record from this table.
The record of devesh here is to be deleted.

here first we create connection with the database,then database is selected using mysql_select_db(),
then delete query is passed to the mysql_query and the table row is deleted.