list all databases on a server

list all databases on a server

<?php
$db = "newdb";
//connect to server with username and password
$connection = @mysql_connect ("localhost","root", "") or die (mysql_error());
//connect to database
$result = @mysql_list_dbs($connection) or die(mysql_error());

$i = 0;
while ($i < mysql_num_rows($result))
{
$name[$i] = mysql_tablename($result, $i);
$dbs = "$name[$i]";
$i++;
echo "$dbs<br>";
}

?>