MySQL: lots of databases

SendTrash

Platinum Member
Apr 18, 2000
2,581
0
76
I am currently trying to modify this existing code for a web application. At first, it seems very messy to me, but one thing that is really bugging me is that it has many databases.. like lots of databases to store different categories of stuff.

In the PHP code there are numerous references to mysql_select_db(), as many as 9 times in some scripts. Now, is this common practice? The applications that I have used before with PHP/MySQL just used one database and had clearly defined tables to separate data.

Am I right to assume that the multiple calls to mysql_select_db() is a very bad design choice? Or is this another common practice to store stuff in MySQL?

BTW, does anyone know of any good MySQL forums? I will be having many questions later
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
i would think that it is uncommon to query many different databases, unless there is a good reason.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
The only time I've ever needed to use more than one database at a time is when I was moving data between two databases.
 

SendTrash

Platinum Member
Apr 18, 2000
2,581
0
76
Originally posted by: Beau
Are they calling to different databases, or are they going to the same one, and making a new connection everytime they run a query?

they are calling a different database everytime.

ex.

they have a database for professor records and class records. When a page needs info from on or the other it calls the mysql database select function.

The more I think about it, it is a severly wrong thing to do right? there is overhead when selecting which database to load right? But then again, isn't a call to select which database used everything a user goes to a new php script? ex. for a new query, the php code still needs to open a new connection.
 
Aug 16, 2001
22,505
4
81
Do you mean that there are many tables within the database or are they actually accessing many different databases?
Many tables makes sense but many databases does not.

<---- database n00b just trying to help.
 

Shuxclams

Diamond Member
Oct 10, 1999
9,286
15
81
Are you refferring to something like this?

$db = mysql_connect("$db_host",$db_uname,"$db_psswd")
or die ("Could not connect to $db_host!");
mysql_select_db("db_name",$db)
or die ("Could not find database named mydomain_rep!");
$result = mysql_query($sql)
or die( mysql_error() );




I am a PHP newbie myself so my coding is still very immature and I do include a lot of that to select a table to grab data from. I am still working on "function" creation that will forego the mysql_connect... but so far I have sucked at it.







SHUX
EDIT: fixed errors.:p
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Shux, your code is connecting to a database called db_table. The table is specified in the query after "FROM", i.e. "SELECT something FROM sometable"