mirror of
https://github.com/standardebooks/web.git
synced 2025-07-16 11:26:37 -04:00
Add Db::QueryFloat()
This commit is contained in:
parent
4cd7a1b72c
commit
55fb675b70
1 changed files with 18 additions and 0 deletions
18
lib/Db.php
18
lib/Db.php
|
@ -36,4 +36,22 @@ class Db{
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single float value for the first column database query result.
|
||||||
|
*
|
||||||
|
* This is useful for queries that return a single float as a result, like `avg(*)` or `sum(*)`.
|
||||||
|
*
|
||||||
|
* @param string $query
|
||||||
|
* @param array<mixed> $args
|
||||||
|
*/
|
||||||
|
public static function QueryFloat(string $query, array $args = []): float{
|
||||||
|
$result = $GLOBALS['DbConnection']->Query($query, $args);
|
||||||
|
|
||||||
|
if(sizeof($result) > 0){
|
||||||
|
return current((Array)$result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue