Re: Selecting databases

From: Date: Tue, 27 Nov 2001 06:24:16 +0000
Subject: Re: Selecting databases
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-75749@lists.php.net to get a copy of this message
> I have a script that needs to be able to choose between 3 different > databases related to a pull down menu. Any ideas about what functions I > should be looking at There's really no need for a function. Most ANSI standard SQL servers will allow you to specify databases on the fly in your queries. So say you had a pulldown menu <SELECT name="database"> <OPTION value="db1">Database 1</OPTION> <OPTION value="db2">Database 2</OPTION> <OPTION value="db3">Database 3</OPTION> </SELECT> With this the name of the database will be transfered to the $database variable upon the form being submitted. Then: mysql_query("SELECT * FROM $database.table_name"); Will run a query on the appropriate database...of course this format is assuming that all the table names will be identical, although if you do have different table names for each database it's very easy to change that dynamically as well. Sincerely, Craig Vincent

« previous php.general (#75749) next »