Skip to content

Commit 115c28e

Browse files
committed
adding precaution behaviour on insert API
1 parent 61b6884 commit 115c28e

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This is a repositories pattern for Codeigniter's Model. All the reuseable functi
1212

1313
Installion are quite easy as following :
1414

15-
1. Download latest release **v1.2.0** from `release` tab or click [here](https://github.com/metallurgical/codeigniter-model-pattern/releases/tag/v1.2.0).
15+
1. Download latest release **v1.2.1** from `release` tab or click [here](https://github.com/metallurgical/codeigniter-model-pattern/releases/tag/v1.2.1).
1616
2. After extracting the archive, it should have 2 folders inside `applications` which are `models` and `traits`
1717
3. Copy all the files inside `models` folder and paste it in your project's `models` folder.
1818
4. Create `traits` folder inside `application` folder from your project directory.
@@ -111,7 +111,7 @@ Insert data into table
111111

112112
**Return**
113113

114-
If success will return last inserted ID, FALSE otherwise
114+
If success, will return last inserted ID, ONLY if the inserted table have an Inceremented ID or will return TRUE if an Incremented ID wasn't existed, FALSE otherwise. Must be noted that, in PHP TRUE also are equal to 1. If the inserted table didn't have an Incremented ID, but the result is return 1,then it mean TRUE.
115115

116116
```Php
117117
// insert into users table without specify table's name

application/models/Model_app.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ function insert ( $arrayData, $table = false ) {
6060
}
6161

6262
if ( $this->db->affected_rows() > 0 ) {
63-
return $this->db->insert_id();
63+
64+
if ( $this->db->insert_id() ) return $this->db->insert_id();
65+
else return TRUE;
6466

6567
} else {
66-
$flag = false;
68+
$flag = FALSE;
6769
return $flag;
6870
}
6971

0 commit comments

Comments
 (0)