PHP - Mysql Delete Statement

the mysql delete statement allows you to remove records from not only one table but also multiple tables using a single delete statement.

mysql delete syntax

                delete     from    table_name

                where     condition ;

note : the mysql where keyword specifies which record should be deleted.if you omit the where statement, in this situation all table records will be deleted.


note : the php use mysqli_query() function to execute the delete statement and send query to a mysql server.

the following example delete data from 'users' table:

 <?php
    
          $host = "localhost";
               
          $_username = "tips";
               
          $_password = "12se";
               
          $_dbname = "employ";               
               
     //--- mysqli procedural style use to connect mysql database server ---
                
 $object = mysqli_connect( $host, $_username, $_password, $_dbname);

  if( $object ){ echo  "<h4>able to connect to database <h4>";
                  
                 }else {              
     
echo "<h1>unable  to connect to database what error: ". mysqli_connect_error()."<h1>"; 
  
                   }
         
  $delete = "delete    from  users  where salary =200000 ";        
                  
mysqli_query( $object, $delete);
              
  ?>

first the users table look like:

first-namelast-namesalary
php-mysql-deleterecord200000
mysql-delete-phpdatas 

after executes the above php script the 'users' table look like:

first-namelast-namesalary
mysql-delete-phpdatas