Skip to content

Modify the user guide of the insert() method to include the second parameter #6660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,18 @@ Saving Data
insert()
--------

An associative array of data is passed into this method as the only parameter to create a new
row of data in the database. The array's keys must match the name of the columns in a ``$table``, while
the array's values are the values to save for that key:
The first parametre is an associative array of data to create a new row of data in the database.
If an object is passed instead of an array, it will attempt to convert it to an array.

.. literalinclude:: model/015.php
The array's keys must match the name of the columns in the ``$table``, while the array's values are the values to save for that key.

The optional second parameter is of type boolean, and if it is set to false, the method will return a boolean value,
which indicates the success or failure of the query.

You can retrieve the last inserted row's primary key using the ``getInsertID()`` method.

.. literalinclude:: model/015.php

update()
--------

Expand Down
7 changes: 7 additions & 0 deletions user_guide_src/source/models/model/015.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
'email' => 'd.vader@theempire.com',
];

// Inserts data and returns inserted row's primary key
$userModel->insert($data);

// Inserts data and returns true on success and false on failure
$userModel->insert($data, false);

// Returns inserted row's primary key
$userModel->getInsertID();