Skip to content

Inserting records

Adding new records into a table is done using the insert() method. The method accepts a single argument that represents a key => value mapped array where the key is the name of the column and the value is the actual value that will be inserted into the column.

Basic usage

php
$query_builder = new QueryBuilder();

$insert = $query_builder->insert([
    'column1' => 'value1',
    'column2' => 'value2',
    // ... more columns and values
]);

If you want to specify the table and execute the insert immediately, you can use the into() method:

php
$result = $insert->into('table_name');

This will insert the data into the specified table and return the number of affected rows (or false on error).

Alternatively, if you want more control or need to build a more complex query, you can specify the table and execute the insert later:

php
$query_builder = new QueryBuilder();

$insert = $query_builder->insert([
    'column1' => 'value1',
    'column2' => 'value2',
    // ... more columns and values
]);

$insert->table('table_name');

Released under the MIT License.