Mysql Update Operation


Update existing records in a table using associative array. Instead of writing long update queries, you needs to pass array of keys(columns) and values(update values) and associative array of conditions with keys as columns and value as column value. This function will automatically create query for you and updates data.

Function Reference :
	              void dbUpdate(string $table_name, assoc. array $update_array [, assoc. array $update_condition_array=array()])) 


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


            $sdb= new SimplifiedDB(); 
            $sdb->dbUpdate("user_roles",array("role_name"=>"Editor","role_description"=>"Edit details"),array("roleid"=>12)); 


Old row will be updated in table.


Debug Operation Result/Output
$sdb->query UPDATE `user_roles` SET `role_name`='Editor',`role_description`='Edit details' WHERE `roleid`='12'
$sdb->rows_affected 1
$sdb->message_info Connected to database

More Examples

           //Example of using array variables to update operation
            $updateRoles["role_description"]="Manages system";
            //update operation on all rows as 'where condtion array' is not passed 
            $sdb->dbUpdate("user_roles",array("role_name"=>"Editor","role_description"=>"Edit posts"));