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]$.