PHP mysql_select_db - to use or not to use

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Bytrix
Forum Newbie
Posts: 1
Joined: Mon Nov 05, 2007 10:55 am

PHP mysql_select_db - to use or not to use

Post by Bytrix »

I've just been wondering after looking at my PHPMyAdmin stats if the mysql_select_db command is actually required in PHP?

I have a number of databases on my main site, some containing just three or four tables and some containing hundreds. Many of my queries use joins between databases and tables and I have always ensured that I specify the database/table/field name in every query to avoid headaches when using joins.

The original mysql_select_db() is still in my database class and selects the 'main' database, but I'm wondering if this is even required, judging by the millions of 'Change Database' queries in the PHPMyAdmin stats I assume that mysql_select_db() physically executes a query to select the database, but seeing as I specify all the database names in my queries is this a wasted query? Should I keep it out or are there any advantages to using the statement?

I was also wondering if there is any real overhead when using joins between databases? As far as I can see from the server's point of view it's doing the exact same number of disk seeks, reads and I can't imagine it'd be any faster if only using one database... but I'm just wanting confirmation from some PHP/MySQL users with more experience...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

MySQL doesn't care if you select a database to use or not. It makes little difference in execution either I would imagine.
Post Reply