There are MYSQL functions you can use. Like this one that resolves the user:
SELECT USER();
This will return something like root@localhost
so you get the host and the user.
To get the current database run this statement:
SELECT DATABASE();
Other useful functions can be found here: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html