Last updated: Tue, Oct 31, 2023 11:23 am
Return to Knowledgebase
# | Parameter | Data Type | Required | Description |
---|---|---|---|---|
1 | $table | string | Yes | Name of the database table |
2 | $fields=[] | associative array | Yes | Field names as keys and corresponding values to be inserted |
3 | $update=false | bool | No | If true, handles duplicate key conflicts |
Data Type | Description of Returned Data |
---|---|
bool | Returns "true" if insert is successful; "false" if unsuccessful |
// Example 1: Inserting a record into the 'users' table
$fields = [
'username' => 'john_doe',
'email' => 'john_doe@example.com',
'password' => 'password123'
];
$result = $db->insert('users', $fields);
// Example 2: Inserting with the update on duplicate key
$result = $db->insert('users', $fields, true);