mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 10:31:59 -04:00
Improve exceptions in DB classes
This commit is contained in:
parent
fdca261133
commit
e14988ff8c
4 changed files with 29 additions and 38 deletions
20
lib/Db.php
20
lib/Db.php
|
@ -15,32 +15,16 @@ class Db{
|
|||
* @return Array<mixed>
|
||||
*/
|
||||
public static function Query(string $query, array $args = [], string $class = 'stdClass'): array{
|
||||
if(!isset($GLOBALS['DbConnection'])){
|
||||
$GLOBALS['DbConnection'] = new DbConnection(DATABASE_DEFAULT_DATABASE, DATABASE_DEFAULT_HOST);
|
||||
}
|
||||
|
||||
if(!is_array($args)){
|
||||
$args = [$args];
|
||||
}
|
||||
|
||||
return $GLOBALS['DbConnection']->Query($query, $args, $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single integer value for the first column database query result.
|
||||
* This is useful for queries that return a single integer as a result, like count(*) or sum(*).
|
||||
* @param string $query
|
||||
* @param array<mixed> $args
|
||||
*/
|
||||
public static function QueryInt(string $query, array $args = []): int{
|
||||
// Useful for queries that return a single integer as a result, like count(*) or sum(*).
|
||||
|
||||
if(!isset($GLOBALS['DbConnection'])){
|
||||
$GLOBALS['DbConnection'] = new DbConnection(DATABASE_DEFAULT_DATABASE, DATABASE_DEFAULT_HOST);
|
||||
}
|
||||
|
||||
if(!is_array($args)){
|
||||
$args = [$args];
|
||||
}
|
||||
|
||||
$result = $GLOBALS['DbConnection']->Query($query, $args);
|
||||
|
||||
if(sizeof($result) > 0){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue