I'm interested to know why you consider this to be very flexible and how

this leaves the selection in the database's hands?

Flexible because I can connect to more than one database on a server
using one connection without having to re-issue a select_db command,
especially in a code container requiring connection to multiple

It leaves the connection on the database side because the selection of
the database is performed in the query rather than in a separate query.
A select_db essentially issues a "use database" query which can be
avoided by including database selection in the query itself.

If I were to implement this and they try some destructive testing/demo 
on a sacrificial database, I'd have to use a whole other server instance

(as all the queries would hardcode in the db name).

I am unsure of what you're after here. We are only using a hard-coded
example but we can certainly improve this by using a class or function.

Is it not more flexible if you omit the table name in every single query

and specify it once in your bootstrap/connection code? Thus doing tests 
on other dbs etc. is a pretty simple switch of the connection code.

Sure it is, unless you have to connect to more than one database in any
given code container. Consider this, I include a database server
connection (one file) and I do not have to do a select_db in other
subsequent files if I include the database name in the SQL query itself;

include("inc/dataConnect.inc"); // containing server connection only

Now in foo.php would you rather;

$theDatabaseSelected = select_db('database', $dbc);
$theQuery = "SELECT foo FROM bar WHERE glorp";


$theQuery = "SELECT a.foo FROM database.bar a WHERE glorp";

Now consider that I have to get information from more than one database
(on the same server) in a single container for display. Do you want to
issue the select_db each time?

$theDatabaseSelected = select_db('database', $dbc);
$theQuery = "SELECT foo FROM bar WHERE glorp";

$theNextDatabaseSelected = select_db('nextDatabase', $dbc);
$theQuery = "SELECT glorp FROM foo WHERE bar";

Or would it be easier to do this?

$theQuery = "SELECT a.foo FROM database.bar a WHERE glorp";
$theNextQuery = "SELECT a.glorp FROM database.foo a WHERE bar";

Also telling the db engine what database you want to use in every query 
is not, IMO, leaving the selection in the the database's hands.

Sure it is, if not you have to use PHP (select_db) to perform the
database selection which sends an additional query ('use database') to
the database system.

In other words, would you query all of the raw data out of the database
and use PHP to process that data when the database can do a much more
effective job of filtering out what you do not need?

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to