- Updates
- Deletes

Laravel's database query builder provides a convenient, fluent interface to creating and running database queries.
- It uses PDO parameter binding to protect your application against SQL injection. There is no need to clean strings passed as bindings.

First, add the DB facade in your controller:
use Illuminate\Support\Facades\DB;
Then, you may use the table() method on the DB facade to begin a query.


To execute Inserts statements with query builder, use the insert() method. It accepts an array of column names and values.
DB::table('users')->insert(['name'=>'MarPlo', 'votes'=>0]);
- To insert several records into the table with a single call to insert(), pass an array of arrays.
 ['name'=>'MarPlo', 'votes'=>0],
 ['name'=>'PloMar', 'votes'=>0]

Auto-Incrementing ID

If the table has an AUTO-INCREMENTING id, use the insertGetId() method to insert a record and then retrieve the ID.
$id = DB::table('users')->insertGetId(['name'=>'MarPlo', 'votes'=>0]);


To update records in MySQL with query builder, use the update() method. It accepts an array of column names and values.
You may also use where() clauses.
DB::table('users')->where('id', 1)->update(['votes'=>1]);
- When updating a JSON column (on databases that support JSON columns), use "->" syntax to access the appropriate key in the JSON object.
DB::table('users')->where('id', 1)->update(['options->enabled'=>true]);

Increment / Decrement

For incrementing or decrementing the value of a column, you may use the increment('col', $nr) / decrement('col', $nr) methods.
The first argument is the 'column name', the second argument is optional, a number to control the amount by which the column should be incremented or decremented.

DB::table('users')->increment('votes', 5);


DB::table('users')->decrement('votes', 5);
- You may also specify additional columns to update during the operation.
DB::table('users')->increment('votes', 1, ['name'=>'MarPlo']);


To delete records in MySQL with query builder, use the delete() method.
You may also use where() clauses.
DB::table('users')->where('votes', '>', 10)->delete();
- If you wish to truncate the entire table (which will remove all rows and reset the auto-incrementing ID to zero), you may use the truncate() method.

- Documentation: Laravel - Database: Query Builder

Daily Test with Code Example

Which tag defines the clickable areas inside the image map?
<map> <img> <area>
<img src="image.jpg" usemap="#map1">
<map name="map1">
  <area shape="rect" coords="9, 120, 56, 149" href="#">
  <area shape="rect" coords="100, 200, 156, 249" href="#">
Which CSS property defines what is done if the content in a box is too big for its defined space?
display overflow position
#id {
  overflow: auto;
Click on the event which is triggered when the mouse is positioned over an object.
onclick onmouseover onmouseout
document.getElementById("id").onmouseover = function(){
  document.write("Have Good Life");
Indicate the PHP variable that contains data added in URL address after the "?" character.
if(isset($_GET["id"])) {
  echo $_GET["id"];
MySQL Query Builder: Insert, Update, Delete

Last accessed pages

  1. html2canvas - Save page screenshoot on server (1146)
  2. querySelector and querySelectorAll (9185)
  3. PHP PDO - Select query, fetch (21562)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (57371)
  5. Creating objects in ActionScript (7754)

Popular pages this month

  1. Making DIV Contents Scroll Horizontally, with multiple Div`s inside (1828)
  2. Contact page - CoursesWeb (1757)
  3. Tabs effect with CSS (1750)
  4. Insert, Select and Update NULL value in MySQL (1031)
  5. PHP getElementById and getElementsByTagName (708)