Skip to content

Commit 05e3fd7

Browse files
committed
fix: Fixed bug on db::count method when no result is found
1 parent a591aad commit 05e3fd7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

‎db.class.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ private static function getInstance()
7373
self::useConnection($connectionName);
7474
}
7575
try {
76-
$instance = new PDO('mysql:host=' . self::$connections[self::$connectionName]['HOST'] . ";dbname=" . self::$connections[self::$connectionName]['NAME'] . ";charset=utf8;", self::$connections[self::$connectionName]['USER'], self::$connections[self::$connectionName]['PASSWORD']);
76+
$instance = new PDO('mysql:host=' . self::$connections[self::$connectionName]['HOST'] . ";dbname=" . self::$connections[self::$connectionName]['NAME'] . ";", self::$connections[self::$connectionName]['USER'], self::$connections[self::$connectionName]['PASSWORD']);
7777
if ($instance) {
7878
$instance->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
7979
//$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
8080
self::updateTotalRequests();
8181
return $instance;
8282
} else {
83+
exit("There's been an error within the database");
8384
return false;
8485
}
8586
} catch (Exception $exception) {
@@ -186,7 +187,15 @@ public static function fetchAll($mixed)
186187
/** It counts the total rows that $mixed have */
187188
public static function count($mixed)
188189
{
189-
return self::encapsulate($mixed)->extra['totalEntries'];
190+
if ($mixed == null) {
191+
return 0;
192+
} else {
193+
if (is_array($mixed)) {
194+
return 1;
195+
} else {
196+
return self::encapsulate($mixed)->extra['totalEntries'];
197+
}
198+
}
190199
}
191200

192201
/** Checks if the given $query returns null. If it returns null or 0, the function return true (is empty) */
@@ -198,7 +207,7 @@ public static function empty($query)
198207
if ($query instanceof dbObject) {
199208
return ($query->getInstance()->rowCount() == 1);
200209
}
201-
if(is_bool($query)){
210+
if (is_bool($query)) {
202211
return !$query;
203212
}
204213
}

0 commit comments

Comments
 (0)