public static function getOne($id, $fields = null)
    {
        $table = self::getTableNameFromClass();

        if ($fields != null && is_array($fields)) {
            $query = "SELECT ". implode(', ', $fields) ." FROM $table WHERE id = $id";
        } else {
            $query = "SELECT * FROM $table WHERE id = $id";
        }

        $res = [];

        $results = Connection::db()->query($query);
        $results->setFetchMode(PDO::FETCH_ASSOC);

        while ($row = $results->fetch()) {
            array_push($res, $row);
        }

        if (!empty($res)) {
            return $res;
        } else {
            throw new PotatoException('There is no user with id '. $id);
        }
    }
public static function getOne($id, $fields = null)
    {
        $table = self::getTableNameFromClass();

        if ($fields != null && is_array($fields)) {
            $query = "SELECT ". implode(', ', $fields) ." FROM $table WHERE id = $id";
        } else {
            $query = "SELECT * FROM $table WHERE id = $id";
        }

        $res = [];

        $results = Connection::db()->query($query);
        $results->setFetchMode(PDO::FETCH_ASSOC);

        while ($row = $results->fetch()) {
            array_push($res, $row);
        }

        if (!empty($res)) {
            return $res;
        } else {
            throw new PotatoException('There is no user with id '. $id);
        }
    }
public static function getOne ( $ id , $ fields = null ) { $ table = self :: getTableNameFromClass ( ) ; if ( $ fields != null && is_array ( $ fields ) ) { $ query = "SELECT " . implode ( ', ' , $ fields ) . " FROM $table WHERE id = $id" ; } else { $ query = "SELECT * FROM $table WHERE id = $id" ; } $ res = [ ] ; $ results = Connection :: db ( ) -> query ( $ query ) ; $ results -> setFetchMode ( PDO :: FETCH_ASSOC ) ; while ( $ row = $ results -> fetch ( ) ) { array_push ( $ res , $ row ) ; } if ( ! empty ( $ res ) ) { return $ res ; } else { throw new PotatoException ( 'There is no user with id ' . $ id ) ; } }
Get one record from the table based on the id provided
@param  integer $id id of the record to be retrieved
@param array $fields array of fields to be retrieved
@return array     associative array of the record retrieved
Get one record from the table based on the id provided