  In this paper, the sufficient and necessary condition for the minimum
distance of the BCH codes over $\mathbb{F}_q$ with length $q+1$ and designed
distance 3 to be 3 and 4 are provided. Let $d$ be the minimum distance of the
BCH code $\mathcal{C}_{(q,q+1,3,h)}$. We prove that (1) for any $q$, $d=3$ if
and only if $\gcd(2h+1,q+1)>1$; (2) for $q$ odd, $d=4$ if and only if
$\gcd(2h+1,q+1)=1$. By combining these conditions with the dimensions of these
codes, the parameters of this BCH code are determined completely when $q$ is
odd. Moreover, several infinite families of MDS and almost MDS (AMDS) codes are
shown. Furthermore, the sufficient conditions for these AMDS codes to be
distance-optimal and dimension-optimal locally repairable codes are presented.
Based on these conditions, several examples are also given.
