Let $T_g$ be the theory of simple graphs (no loop, undirected) in the language $\mathcal{L}=\{R\}$ where $R$ is a binary relation. Let $T$ be an $\mathcal{L}$-theory such that $T\models T_g$ and every model of $T$ is connected.
How can we prove that there is a number $N_T\in \mathbb{N}$ such that for all model $\mathcal{M}\models T$ and for all $a,b\in M$, there is a path from $a$ to $b$ of length at most $N_T$?
I know that I should use the Compactness theorem, but I do not know how!
For each $n\in \mathbb{N}$, let $\phi_{n+1}(x,y)$ be the following formula $$x\neq y\wedge \exists v_1,...,v_n\left(x=v_1\wedge\bigwedge_{i=1}^{n-1}(R(v_i,v_{i+1})\vee v_{i+1} = v_i)\wedge v_n=y\right)$$ For $\mathcal{M}\models T_g$ and $a,b\in M$, $\mathcal{M}\models\phi_{n+1}(a,b)$ if and only if $a\neq b$ and there is a path between $a$ and $b$ of length at most $n$.
Suppose, towards a contradiction, that for all $n\in \mathbb{N}$ there exist a model $\mathcal{M}\models T$ and $a,b\in M$ such that $\mathcal{M}\models \neg\phi_n(a,b)$.
Consider the $\mathcal{L}^*$-theory $T^* := T\cup \left\{\neg\phi_{n+1}(c_1,c_2) : n<\omega \right\}$ where $\mathcal{L}^*=\mathcal{L}\cup \left\{c_1, c_2 \right\}$ and $c_1, c_2$ are new constant symbols. If we show that $T^*$ has a model, then $T$ has a model which is not connected and this is a contradiction. So it's enough to show that $T^*$ is satisfiable.
Let $T_0$ be a finite subset of $T^*$. Let $T_0\cap \left\{\neg\phi_{n+1}(c_1, c_2) : n<\omega \right\}=\left\{\neg\phi_{n_1}(c_1, c_2),\dots, \neg\phi_{n_r}(c_1, c_2) \right\}$. Let $n^*=\max\left\{ n_1,\dots, n_r \right\}$. By assumption there is a model $\mathcal{M}\models T$ such that $(\mathcal{M}, c_1^\mathcal{M}, c_2^\mathcal{M})\models \phi_{n^*}(c_1,c_2)$. So $(\mathcal{M}, c_1^\mathcal{M}, c_2^\mathcal{M})\models T_0$. Thus $T^*$ is finitely satisfiable and so by the Compactness theorem $T^*$ has a model, say $\mathcal{M}^*$. Therefore $\mathcal{M}^*$ is a model of $T$ that is not connected. This is a contradiction.