When does the relative differential $df=0$ imply that $f$ comes from the base? Let $A \to B$ be a map of commutative rings, and $d : B \to I/I^2$ be
defined by $df = f\otimes 1 - 1\otimes f$, where $I$ is the kernel of
$B \otimes_A B \to B$, as in [Hartshorne II.8].

If $df=0$, I would like to infer that $f \in A$, i.e. "if the
  derivative is zero, the function is constant".

This is certainly $\bf false$, 
e.g. $A = {\mathbb F}_p$, $B = A[x]$, and $f=x^p$.
There $B\otimes_A B\to B$ is $A[x_1,x_2] \mapsto A[x]$, with 
$I = \langle x_1 -x_2\rangle \ni x_1^p - x_2^p = f\otimes 1 - 1\otimes f$.
(That is, not only is $f\otimes 1 - 1\otimes f$ in $I^2$, it's in $I^p$.)

What is the right condition, then, on $A\to B\ $? My primary interest is
  in $A = {\mathbb Z}[1/d]$.

 A: I will rather regard $I/I^2$ as $\Omega_{B/A}$, the module of differential forms. 
First some necessary conditions. If $D$ is a sub-$A$-algebra of $B$ such that $\Omega_{D/A}=0$ (e.g. $D$ is a localization of $A$ or étale over $A$), the canonical map $\Omega_{D/A}\otimes_D B\to \Omega_{B/A}$ shows that $df=0$ for all $f\in D$. So if $A$ is a field (of characteristic $0$), you want it to be algebraically closed in $B$. If $A$ is not a field, to avoid $B$ to contain a localization of $A$, you almost want to suppose $\mathrm{Spec} B\to \mathrm{Spec}A$ be surjective. 
These being said, now a sufficient condition. 

Suppose $A$ is noetherian, integrally closed of characteristic $0$, $B$ is an integral domain, $\mathrm{Spec} B\to \mathrm{Spec}A$ is surjective, and its generic fiber is smooth of finite type and geometrically integral. Then the kernel of $B\to \Omega_{B/A}$ is equal to $A$. 

Proof. 
(1) Let $C$ be the kernel of $d : B\to \Omega_{B/A}$. This is a sub-$A$-algebra of $B$. The canonical exact sequence 
$$ \Omega_{C/A}\otimes_C B\to \Omega_{B/A}\to \Omega_{B/C}\to 0$$
implies that $\Omega_{B/A}\to \Omega_{B/C}$ is an isomorphism because the first map is identically zero ($dc\otimes b\mapsto bdc=0$ if $c\in C$). 
(2) Let $K=\mathrm{Frac}(A)$, $L=\mathrm{Frac}(B)$. Let us first show that $E:=\mathrm{ker}(L\to\Omega_{L/K})$ equals to $K$. Note that $E$ is a field. Applying (1) to the situation $A=K$ and $B=L$, we see that $\Omega_{L/K}\to \Omega_{L/E}$ is an isomorphism. This map is $L$-linear, and $\dim_L\Omega_{L/K}$ is the transcendental degree of $L$ over $K$ (here we use the characteristic zero hypothesis). Similarly for $L/E$. Hence $E$ is algebraic over $K$. But $B_K$ is geometrically integral over $K$, this forces $E=K$ (otherwise $L\otimes_K E$ is not integral). 
(3) Let us show $C_K:=C\otimes_A K$ equals to $K$. Tensoring the exact sequence of $A$-modules
$$ 0\to C\to B\to \Omega_{B/A}$$ 
by $K$, we get the exact sequence
$$ 0\to C_K \to B_K \to \Omega_{B_K/K}. $$ 
First suppose $B_K$ is smooth over $K$. As $\Omega_{L/K}$ is a localization of $\Omega_{B_K/K}$ and the latter is a free (hence torsion free) $B_K$-module, the map $\Omega_{B_K/K}\to \Omega_{L/K}$ is injective. By (2) we then get $C_K=K$. In the general case, some dense open subset $U$ of $\mathrm{Spec}(B_K)$ is smooth. If $f\in B_K$ satisfies $df=0$ in $\Omega_{B_K/K}$, then $d(f_{|U})=0$ in $\Omega_{U/K}$. So $f{|_U}\in K$. As $B_K\to O(U)$ is injective, $f\in K$. 
(4) Let us show $C=A$. We have $C\subseteq B\cap K$ (in fact the equality holds). So we have to show $B\cap K=A$. Let $g\in B\cap K$ viewed as a rational function on $\mathrm{Spec}(A)$. Then $A\subseteq A[g]\subseteq B$. For any prime ideal $Q$ of $B$, $g$ is regular at the point $Q\cap A$. So the image of $\pi : \mathrm{Spec}(B)\to \mathrm{Spec}(A)$ is contained in the complementary of the pole divisor of $g$. So the latter is empty by the surjectivity hypothesis on $\pi$. Therefore $g$ is a regular function (here we use the normality of $A$) and $C=A$. 
Add Suppose $A, B$ are integral domains of characteristic $0$, $B_K$ is finitely generated over $K=\mathrm{Frac}(A)$, and $\Omega_{B_K/K}$ is torsion free over $B_K$. Then we proved above that the kernel of $d: B\to\Omega_{B/A}$ is contained in $B\cap K^{alg}$. 
Add 2 One can remove free or torsion-free condition on $\Omega_{B_K/K}$. The proof is a little modified in the step 3. We just notice that any integral variety in characteristic $0$ has a dense open subset which is smooth ! 
