|
9 | 9 | * 2021年08月17日 -> Made a few improvements within base core functions
|
10 | 10 | * 2021年11月16日 -> Fixed Fetch method when same SQL is called more than once
|
11 | 11 | * 2022年01月22日 -> Fixed Fetch method when same SQL is called in a simple way. Also added a way to RETRIEVE data if same SQL is sent again
|
| 12 | + * 2022年01月24日 -> Fetch method is getting more complicated to solve. Third time in a row. |
12 | 13 | */
|
13 | 14 |
|
14 | 15 | class db
|
@@ -139,10 +140,14 @@ private static function encapsulate($mixed, $simple = false)
|
139 | 140 | $instance = new dbObject(self::getInstance()->query($mixed), array("key" => $key, "simple" => $simple));
|
140 | 141 | self::$object[$key] = $instance;
|
141 | 142 | }
|
142 | | - if (self::$object[$key]->extra["rows"] + 1== self::$object[$key]->extra["totalEntries"] && self::$object[$key]->extra["totalEntries"] <= 0) { |
| 143 | + if (self::$object[$key]== "unsetted") { |
143 | 144 | unset(self::$object[$key]);
|
144 | 145 | return false;
|
145 | 146 | }
|
| 147 | + /*if (self::$object[$key]->extra["rows"] + 1 == self::$object[$key]->extra["totalEntries"] && self::$object[$key]->extra["totalEntries"] <= 0) { |
| 148 | + unset(self::$object[$key]); |
| 149 | + return false; |
| 150 | + }*/ |
146 | 151 | return self::$object[$key];
|
147 | 152 | }
|
148 | 153 | if ($mixed instanceof dbObject) {
|
@@ -187,6 +192,12 @@ public static function fetchAll($mixed)
|
187 | 192 | }
|
188 | 193 | }
|
189 | 194 |
|
| 195 | + public static function unsetObject($object) |
| 196 | + { |
| 197 | + self::$object[$object->extra['key']] = "unsetted"; |
| 198 | + unset(self::$object[$object->extra['key']]); |
| 199 | + } |
| 200 | + |
190 | 201 | /** It counts the total rows that $mixed have */
|
191 | 202 | public static function count($mixed)
|
192 | 203 | {
|
@@ -413,10 +424,11 @@ public static function page($echo = true, $class = "")
|
413 | 424 | $buttons[] = str_replace(array("{rel}", "{target}", '{text|number}', '{active}', '{disabled}'), array("rel='next'", $url . "?" . http_build_query($_GET), $words["next"], '', ''), $htmlButton);
|
414 | 425 | }
|
415 | 426 | }
|
| 427 | + $return = str_replace(array("{additional}", "{buttons}"), array($words['class'], implode("", $buttons)), $htmlWrapper); |
416 | 428 | if ($echo) {
|
417 | | - echo str_replace(array("{additional}", "{buttons}"), array($words['class'], implode("", $buttons)), $htmlWrapper); |
| 429 | + echo $return; |
418 | 430 | } else {
|
419 | | - return true; |
| 431 | + return $return; |
420 | 432 | }
|
421 | 433 | }
|
422 | 434 | }
|
@@ -470,7 +482,7 @@ public static function setFriendlyURL($FriendlyURLInstance)
|
470 | 482 | /** It will retrieve the collumns of the given $table */
|
471 | 483 | private static function getTableCollumns($table)
|
472 | 484 | {
|
473 | | - return self::fetchAll(self::query("DESCRIBE $table")); |
| 485 | + return self::fetchAll("DESCRIBE $table;"); |
474 | 486 | }
|
475 | 487 |
|
476 | 488 | /** It will fix invalid $data keys before insert them on the $table. It removes not used keys inside $data, and bind a empty string if a specific $key that exists on the table, doesn't exist on $data */
|
@@ -766,13 +778,21 @@ public static function getInstance()
|
766 | 778 | public function getData($all = false)
|
767 | 779 | {
|
768 | 780 | if ($all) {
|
769 | | - return $this->getInstance()->fetchAll(PDO::FETCH_ASSOC); |
| 781 | + $data = $this->getInstance()->fetchAll(PDO::FETCH_ASSOC); |
| 782 | + db::unsetObject($this); |
| 783 | + return $data; |
770 | 784 | }
|
771 | 785 | if (!$this->extra['simple']) {
|
772 | 786 | $this->extra["rows"]++;
|
773 | 787 | $data = $this->getInstance()->fetch(PDO::FETCH_ASSOC);
|
| 788 | + if ($this->extra['rows'] == $this->extra['totalEntries']) { |
| 789 | + db::unsetObject($this); |
| 790 | + } |
774 | 791 | return $data;
|
775 | 792 | } else {
|
| 793 | + if (empty($this->data)) { |
| 794 | + return false; |
| 795 | + } |
776 | 796 | return $this->data[0];
|
777 | 797 | }
|
778 | 798 | }
|
|
0 commit comments