Integrating $\int\frac1{x(x+2)}dx$ and $\int\frac1{e^x+2}dx$. What am I doing wrong? I have the following 2 questions to integrate as part of my practice.
(i) $\displaystyle \int\frac1{x(x+2)}dx$
(ii) $\displaystyle \int\frac1{e^x+2}dx$
and I have tried it myself but I am not getting the answer required
(i) $\displaystyle \frac12\ln x-\frac12\ln(x+2)+C$
(ii) $\displaystyle \frac12x-\frac12\ln(e^x+2)+C$
Below are my workings
(i) $\displaystyle \int\frac1{x(x+2)}dx\;=\;\int\frac1{x^2+2x}dx\;=\;\frac{\ln(x^2+2x)}{2x+2} +C$
(ii) $\displaystyle \int\frac1{e^x+2}dx\;=\frac{\ln(e^x+2)}{e^x} +C$
May I know what am I doing wrong such that my answer differs? 
 A: For i) use partial fractions; note that $$\frac{1}{x(x+2)}=\frac{\frac 12}{x} -\frac{\frac12}{x+2}$$ So your integral becomes:
$$\int{\frac{1}{x(x+2)}dx}=\frac12\bigg[\int \frac 1x dx-\int \frac{1}{x+2}dx\bigg]$$
For the second, substitute $$u=e^x\to dx = \frac{du}{u}$$
Then your integral becomes:
$$\int\frac{1}{e^x+2}dx=\int{\frac{1}{u(u+2)}du}$$ which we just solved in i)
A: For i):
With the constant rule 'trick', what you are effectively doing is:
$$\int \frac{1}{x^2+2x} \ dx$$
When $u = x^2+2x, du = 2x+2 \ dx, dx = \frac{du}{2x+2}$, we have: 
$$\int \frac{1}{u(2x+2)} \ du, $$
and since you cannot get the $2x+2$ part to be in terms of $u$, this 'trick' does not work.
What you can do is to use partial fractions: 
$$\frac{A}{x} + \frac{B}{x+2} = \frac{1}{x(x+2)}$$
$$A(x+2) + Bx = 1 \tag{1}\label{eq1}$$
$$(A+B)x + 2A = 1 \tag{2}\label{eq2}$$
This is an identity – it will hold for any $x$. So when $x = 0, A = \frac{1}{2}$ from equation $2$, and when $x = -2$, $B = -\frac{1}{2}$ from equation $1$. 
Can you integrate it now?
A: The substitution rule is $$\int f(g(x)) \, g'(x) \,{\rm d}x = \int f(u) \,{\rm d}u.$$  In particular, when $f(x) = 1/x$, $$\int \frac{g'(x)}{g(x)}\,{\rm d}x = \int \frac{{\rm d}u}{u} = \log u + C = \log(g(x)) + C.$$
What you are trying to do is to "dividing both sides by the derivative of $g$": $$\int \frac{1}{g(x)}\,{\rm d}x = \frac{\log(g(x))}{g'(x)} + C. \tag{OP's wrong method}$$  As the first comment suggests, differentiating both sides with respect to $x$ allows you to see the error.
