Breaking

LightBlog

Friday 27 February 2015

PHP Delete Data From MySQL


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.
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

                                             
delete data in php mysql

 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