Find and print the host name of the mysql in wordpress

933 views Asked by At

I am trying to find the hostname of the sql using wordpress. ie I wanted to print the 'localhost' from 'http://**localhost**/velocity/wordpress/?page_id=4'

I tried the function home_get_url(), but I got the entire path as shown above. When I was trying with gethostname() I got my PC name. '

Please help. I am a fresher to wordpress.

2

There are 2 answers

2
Sougata Bose On BEST ANSWER

You can use $_SERVER['HTTP_HOST']

For http://localhost/velocity/wordpress/?page_id=4 it will return http://localhost

1
praveen_programmer On

Hope it will help you .

printf("MySQL host info: %s\n", mysql_get_host_info());

You can also try .

<?php
echo gethostname(); // may output e.g,: sandie

// Or, an option that also works before PHP 5.3
echo php_uname('n'); // may output e.g,: sandie
?>

For more info . http://www.php.net/manual/en/function.gethostname.php