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

You need to set $parameter_types as data type of where condition columns before using this function. For examples if you have five columns then you need to pass data type of each column like "sssis" where s denotes the string data type, i denotes numeric data type.


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 old 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->parameter_types="i";
          $sdb->dbDelete("user_roles",array("roleid"=>28)); 
          ?> 

Result

Old row will be deleted in table.

Debuging

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

More Examples

 
         $whereRoles["roleid"]=15;
         $sdb->parameter_types="i";
         $sdb->dbDelete("user_roles",$whereRoles);