db::min PHP Method

min() static public method

Gets the minimum value in a column of a table
static public min ( string $table, string $column, mixed $where = null ) : mixed
$table string The table name
$column string The name of the column
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
return mixed
    static function min($table, $column, $where = null)
    {
        $sql = 'SELECT MIN(' . $column . ') AS min FROM ' . self::prefix($table);
        if (!empty($where)) {
            $sql .= ' WHERE ' . self::where($where);
        }
        $result = self::query($sql, false);
        $result = self::fetch($result);
        return a::get($result, 'min', 1);
    }

Usage Example

Example #1
0
 public function testMin()
 {
     $this->assertEquals(1, db::min('users', 'id'));
 }