I've "fixed" the problem:
I was calling mysql functions from my php script. The apache module version of php has no problems accessing those, but the cgi version does. When I realized this, I started looking for a solution. I found a bunch of "ugly" cumbersome work-arounds and one which was so simple, that I decided to use it.
Now, if I want to run a script from the commandline I simply call:
lynx -dump blablabla.php
I hope this helps someone. 😉