A lot of hosting companies don't have the sql server on the same host as the web-servers. getting the name of the host that the php script is running on may not help you.
You can try looking at the $_SERVER['SERVER_ADDR'] information in the $_SERVER array. But that would be the same as just using 'localhost' for your server address.
But php has no way of guessing where an SQL server might reside, because it could be anywhere on the internet/LAN/localhost