Hi All,
Recently I needed to update, delete and select using RAW query in Laravel 5.0. When I searched the internet the only query I was able to find out is the select query but I need to accomplish both update and delete also.So after little more R&D I came to know I can use the same query to accomplish that with very little change.
To demonstrate to you how we can achieve that I have written down the syntax of all.
Syntax:-
1) Select :- To select records from a table.
$response = DB::select(DB::raw("SELECT * FROM userinfo"));
2) Update :- To update a records of a table.
$finalResult = DB::update(DB::raw("UPDATE {$tableName} SET comment='{$correctData['comment']}', modified='{$correctData['modified']}' {$updateCondition}"));
3) Delete :- To delete a records of a table.
$finalResult = DB::delete(DB::raw("DELETE FROM {$tableName} WHERE {$deleteCondition}"));
//To chect if the query executed properly you may use the following syntax
if($finalResult == 1){
//SUCCESS
} else {
//ERROR
}
0 Comment(s)