Database Class Methods

insert() method

Purpose:
The insert() method is for specifying the column names you want to insert into.

Format:

in(column | string(column1, column2, column3, ...) | array(column1, column2, column3, ...))

Examples:

// Insert two users 'Bob' and 'John' into the users table.
$db ->insert('name, email, type')
    ->into('users')
    ->values([['bob', 'bob@gmail.com', 'admin'], ['john', 'john@gmail.com', 'admin']])
    ->exec();

into() method

Alias:
This method is an alias of table().

Purpose:
The into() method is for selecting the table(s) you want to insert data into.

Format:

into(table_name | array(table_name1, table_name2, ...))

values() method

Purpose:
The values() method is for specifying the values you want to insert when executing an insert statement. It expects either a single array when inserting a single row of data, or an array of arrays when inserting multiple rows of data.

Format:

values(array(value1, value2, ...) | array(array(value1, value2, ...), array(value1, value2, ...)))

Examples:

// Insert a single row of data.
$db ->insert('name, email, type')
    ->into('users')
    ->values(['bob', 'bob@gmail.com', 'admin'])
    ->exec();

// Insert multiple rows of data
$db ->insert('name, email, type')
    ->into('users')
    ->values([['bob', 'bob@gmail.com', 'admin'], ['john', 'john@gmail.com', 'admin']])
    ->exec();

// OR insert multiple rows of data by calling values() more than once...
$db ->insert('name, email, type')
    ->into('users')
    ->values(['bob', 'bob@gmail.com', 'admin'])
    ->values(['john', 'john@gmail.com', 'admin'])
    ->exec();