Skip to content

Commit

Permalink
Merge pull request #6660 from domaingenerator/modify-insert-method-de…
Browse files Browse the repository at this point in the history
…tails

Modify the user guide of the insert() method to include the second parameter
  • Loading branch information
kenjis authored Oct 17, 2022
2 parents f6a0343 + caebceb commit 62c560b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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' => '[email protected]',
];

// 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();

0 comments on commit 62c560b

Please sign in to comment.