Breaking

LightBlog

Saturday 4 July 2015

MySQL DELETE Query PHP Tutorial

MySQL  DELETE Query

Just we have to insert the data in database using PHP. If we want to delete unwanted data in database then you can use DELETE command. It is typically used in conjugation with where clause to delete only those records that matches specific criteria.
                                 
MySQL  DELETE Query  PHP Tutorial
Syntax:
DELETE FROM table_name WHERE [condition]

  • You can specify any condition using WHERE clause.
  • You can delete records in single table at a time.
  • If WHERE clause is not specified then all records will be deleted in SQL table.


Student name
Age
Id
Amandeep singh
25
4
Deepak kumar
26
3
Lakwinder singh
30
2
Pardeep singh
25
1

                                             

 You can use SQL DELETE command with or without WHERE clause into PHP function mysql_query. This function will execute SQL command in similar way it is executed at mysql > prompt .
Example:
<?php
$con=mysql_connect(“localhost”, “deep “, 12345);
if (!$con)
{
die(“could not be connect the database” . mysql_error());
}
echo “ connected successfully “;
mysql_select_db ( “student”);
$sql = “ DELETE From student1 Where stu_name =’pardeep singh’;
$retrive =mysql_query ($sql, $con );
If (!$retrive)
{
die (“could not be Delete  data in database ”);
}
echo “ DELETE data successfully “;
mysql_close ($con);
?>


Adbox