PHP & Counting Databases

I was just wondering if it’s possible to count the number of databases, say you have a root MySQL user, is it possible?

Basically I’ve been coding a forum hosting script, each forum has it’s own database and I was thinking, if it’s possible it’d save time rather than having to add a new id to a database.

Thanks for any responses.

I am not I have understood your question well, but if you want to know how many databases are there in the system, simply type show databases in your MySQL terminal. Or write small script with the said SQL in it showing on screen all databases in any given root user.

<?php
$link = mysql_connect('localhost', 'user_name', 'password');
$db_list = mysql_list_dbs($link);

$no_databases=count($db_list);

echo "<p>There are $no_databases on the MySQL server, they are:</p>";

while ($row = mysql_fetch_object($db_list)) {
     echo $row->Database . "<br />";
}
?>

That will give you a count off all the databases on the server (take off 2 from the count to account for the “information_schema” and “mysql” databases, both of which you should not touch as messing around with either can break MySQL.

Bad idea!
I’ve developed a pretty large forum hosting site which offers different forum types (BB2, BB3, WBBLite etc.) and you’ll get a hell of a mess when using a single database per user-forum.
ALso - counting databases will kill your server when you’re having more DBs, other statements like SHOW TABLES also.
And, one really important thing: don’t copy all those PHP scripts for each forum installation!
It’s a bit tricky, but doable, to host one version of the scripts and have multiple installs with separate upload/cache folders etc.
It’ll gain you a lot of performance and you’re able to use OPCode-Caching lkike APC, which wouldn’t kick in when copying those files over and over.

Thanks for that! Got how to do it.

=========

The script we’re using is TinyBB, which is one coded by myself. For the forum host, we’re using the same files for each forum, except the extra files coded in to balance the accessing of the files. Tested with 50 users on 4 forums and it works at 100% speed and the server load is low.

Thanks for the info though.