Mysql Delete Operation

Description

Delete records in a table using associative array. Instead of writing long delete queries, you needs to pass associative array of conditions with keys as columns and value as column value. This function will automatically create query for you and deletes records.

Function Reference :
 
             	void dbDelete(string $table_name [, assoc. array $delete_where_condition=array()]);
             

Parameters

Name Type Required Parameter Info Example
table_name string Yes The name of the table to delete records any table name like employee_table,user_table
delete_where_condition associative array Optional Associative array with key as column name and values as column value pass where condition to delete old row. array("userid"=>15)

Examples

 
          <?php
         $sdb= new SimplifiedDB(); 
         $sdb->dbConnect("localhost","username","password","dbuser");
         $sdb->dbDelete("user_roles",array("role_id"=>12)); 
         ?> 
         

Result

Old row will be deleted in table.

Debuging

Debug Operation Result/Output
$sdb->query DELETE FROM `user_roles` WHERE `roleid`='12'
$sdb->last_insert_id 0
$sdb->rows_affected 1
$sdb->message_info Connected to database
$sdb->error_info

More Examples

                //Example of delete operation with where condition array as parameter
                $whereRoles["roleid"]=15;
                $sdb->dbDelete("user_roles",$whereRoles);
                
                //Delete operation without where condition, all rows will be deleted from that table
                $sdb->dbDelete("user_roles");