diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index 19454b96b262..19059be46b9d 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -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() -------- diff --git a/user_guide_src/source/models/model/015.php b/user_guide_src/source/models/model/015.php index 23414a8c9a01..a1b013fff974 100644 --- a/user_guide_src/source/models/model/015.php +++ b/user_guide_src/source/models/model/015.php @@ -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();