Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 962edce

Browse filesBrowse files
committed
update: Improved a bit class performance
1 parent fe40f06 commit 962edce
Copy full SHA for 962edce

File tree

Expand file treeCollapse file tree

1 file changed

+17
-17
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-17
lines changed

‎db.class.php

Copy file name to clipboardExpand all lines: db.class.php
+17-17Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private static function getInstance($key = false)
8585
$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']);
8686
if ($instance) {
8787
$instance->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
88+
$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
8889
self::updateTotalRequests();
8990
return $instance;
9091
} else {
@@ -269,6 +270,9 @@ public static function empty($query)
269270
}
270271
}
271272
if ($query instanceof dbObject) {
273+
if (is_bool($query->getInstance())) {
274+
return true;
275+
}
272276
return ($query->getInstance()->rowCount() == 0);
273277
}
274278
}
@@ -580,7 +584,7 @@ private static function fixDataCollumns($data, $table, &$newData = array(), $mod
580584
foreach ($collumns as $collumn) {
581585
if ($collumn['Key'] == "PRI" && $collumn['Extra'] == "") {
582586
$id = self::fetch(self::query("SELECT $collumn[Field] FROM $table ORDER BY $collumn[Field] DESC LIMIT 1"));
583-
$newData[$collumn['Field']] = ++$id['id'];
587+
$newData[$collumn['Field']] = ++$id[$collumn['Field']];
584588
} else if ($collumn['Key'] == "PRI" && $collumn['Extra'] !== "") {
585589
unset($newData[$collumn['Field']]);
586590
}
@@ -593,25 +597,22 @@ private static function fixDataCollumns($data, $table, &$newData = array(), $mod
593597
} else {
594598
if (preg_match("/int/", $collumn['Type']) && !isset($newData[$collumn['Field']]) && $collumn['Extra'] == "") {
595599
$newData[$collumn['Field']] = 0;
596-
}
597-
if (preg_match("/char|text/", $collumn['Type'])) {
600+
} else if (preg_match("/char|text/", $collumn['Type'])) {
598601
$newData[$collumn['Field']] = "";
599-
}
600-
if (preg_match("/date|time|year/", $collumn['Type'])) {
602+
} else if (preg_match("/date|time|year/", $collumn['Type'])) {
601603
if ($collumn['Type'] == "datetime") {
602-
$newData[$collumn['Field']] = "0000-00-00 00:00:00";
603-
}
604+
$newData[$collumn['Field']] = self::dateTime();
605+
} else
604606
if ($collumn['Type'] == "date") {
605-
$newData[$collumn['Field']] = "0000-00-00";
606-
}
607+
$newData[$collumn['Field']] = self::date();
608+
} else
607609
if ($collumn['Type'] == "year") {
608-
$newData[$collumn['Field']] = "0000";
609-
}
610+
$newData[$collumn['Field']] = self::date("Y");
611+
} else
610612
if ($collumn['Type'] == "timestamp") {
611613
$newData[$collumn['Field']] = time();
612614
}
613-
}
614-
if (preg_match('/enum|set/', $collumn['Type'])) {
615+
} else if (preg_match('/enum|set/', $collumn['Type'])) {
615616
preg_match("/(?:[set|enum])(?:\()(.*?)(?:\))/", $collumn['Type'], $matches);
616617
$values = explode(",", $matches[1]);
617618
$value = substr($values[0], 1);
@@ -710,12 +711,11 @@ public static function insert($data, $table, $additional = array())
710711
$stmnt->execute();
711712
self::updateTotalRequests();
712713
self::$id = $instance->lastInsertId();
713-
unset($stmnt, $instance);
714-
return true;
714+
return (self::$id != 0);
715715
}
716716
return false;
717717
} catch (Error $e) {
718-
throw ("An error ocurred: " . $e);
718+
throw ($e);
719719
return false;
720720
}
721721
}
@@ -757,7 +757,6 @@ public static function update($data, $table, $rules = array(), $additional = arr
757757
foreach ($newData as $key => $value) {
758758
self::set($stmnt, $key, $value);
759759
}
760-
761760
if (!empty($rules)) {
762761
foreach ($rules as $key => $value) {
763762
self::set($stmnt, "rule_" . $key, $value);
@@ -809,6 +808,7 @@ public static function delete($table, $rules = array())
809808
}
810809

811810
/**
811+
* TODO
812812
* @param string Search term to get all words
813813
* @return array Array containing all words and combinations with the given words
814814
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.