在wordpress中查找并打印mysql的主机名

在wordpress中查找并打印mysql的主机名

问题描述:

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.

我正在尝试使用wordpress找到sql的主机名 strong>。 即我想从'http:// ** localhost ** / velocity / wordpress /?page_id = 4' code> p> 打印' localhost em>'

我尝试了函数 home_get_url() strong>, em>,但我得到了如上所示的整个路径。 当我尝试使用 gethostname()时 / strong>我的 PC名称 em>。 ' p>

请帮忙。 我是更新鲜的wordpress em>。 p> div>

You can use $_SERVER['HTTP_HOST']

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

Hope it will help you .

printf("MySQL host info: %s
", 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