treehouse : what would you like to learn today?
Web Design Web Development iOS Development
  • in my sidebar.php, I would like to display the WordPress database name used? can I do it and if so, how? trying to find information like this in the codex is like going through a haystack looking for a needle.

    Al

  • Re-posting.

  • <?php
    // Usage without mysql_list_dbs()
    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    $res = mysql_query("SHOW DATABASES");
    
    while ($row = mysql_fetch_assoc($res)) {
        echo $row['Database'] . "\n";
    }
    
    // Deprecated as of PHP 5.4.0
    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
    $db_list = mysql_list_dbs($link);
    
    while ($row = mysql_fetch_object($db_list)) {
         echo $row->Database . "\n";
    }
    ?>