You are here: Re: How can i display a list of mysql databases in php? « PHP SQL « IT news, forums, messages
Re: How can i display a list of mysql databases in php?

Posted by NC on 02/22/06 21:35

Ninja_Monkey wrote:
> ill show you the code im trying.
>
> $connection = mysqli_connect($_SESSION['host'], $_SESSION['user'],
> $_SESSION['pass']);
> $sql = "SHOW DATABASES";
> $result = mysqli_query($connection, $sql);
> $dblist = mysqli_fetch_array($result, MYSQLI_NUM); # A PRINT OF THIS
> SAYS Array
> $c = 0;
> while (count($dblist) > $c) {
> print_r($dblist[$c] . "<br>\n"); #THIS PRINTS OUT AS:
> "information schema". IT ONLY PRINTS 1 aswell.
> $c++;
> }
> $result = NULL;
> @mysqli_free_result($result);
> mysqli_close($connection);
>
> What is an information Schema??? and why does this not work.

Basically, because you think mysqli_fetch_array() returns a list of
databases (it doesn't). A SHOW DATABASES query returns a list of
databases, with each name in its own record. So you need to read
through the result set; something like this:

$connection = mysqli_connect($_SESSION['host'],
$_SESSION['user'], $_SESSION['pass']);
$sql = "SHOW DATABASES";
$result = mysqli_query($connection, $sql);
while ($record = mysqli_fetch_array($result, MYSQLI_NUM)) {
echo $record[0], "<br>\r\n";
}
mysqli_free_result($result);
mysqli_close($connection);

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация