It is given that the hydrostatic pressure is directly proportional to the following terms
P=Kdxhygz............(1)
K=constant
Writing dimensional formula of pressure, density, height and acceleration due to gravity as
[MLT2]=[ML3]x[L]y[LT2]z
On comparing there powers, we get
x=1
z=1
&y=1
Equation (1) becomes
P=dgh