diff --git a/src/Libs/Model.php b/src/Libs/Model.php index bfb93dc..24a850d 100644 --- a/src/Libs/Model.php +++ b/src/Libs/Model.php @@ -176,6 +176,10 @@ class Model $vars = json_encode(static::$dbQueryVariables); + if ($resetQuery) { + static::resetQuery(); + } + throw new Exception( "\nError at query to database.\n" . "Query: $query\n" . @@ -1008,7 +1012,9 @@ class Model public static function orderBy(string $value, string $order = 'ASC'): static { if ($value == "RAND") { - static::$dbQuery['orderBy'] = 'RAND()'; + $random = static::db()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql' ? 'RAND()' : 'RANDOM()'; + static::$dbQuery['orderBy'] = $random; + return new static(); }