[thelist] CF: Determining which DB used.

.jeff jeff at members.evolt.org
Wed Sep 12 09:17:51 CDT 2001


frank,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Frank
>
> The apps I write are cross platform, thus different DBs
> come into play. Access or SQL 7 on PC, and MySQL on
> Linux. Is there a way of automatically determining what
> database I'm using without having to resort to creating
> a global variable and changing it every time I move my
> app? It's a little thing that would make the transitions
> smoother.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

i know of no way to actually query the database to find out what it is.

the simplest way is to only use sql that will run on all platforms.  this is
next to impossible to achieve though.

you might be able to query information from the server or cgi scopes about
the machine the code is running on and run different queries based on this
information.  try looking at server.OS.name, server.OS.version, and
cgi.server_software.  btw, anybody know why server and variables scopes
aren't structures?

my suggestion would be to create those global variables you mention -- one
for datasource, one for dbtype, and maybe another for dbserver.  then,
whenever you run a query, check the dbserver variable and run a query
designed for the currently connected database.

it's a slight bit more work, but it's a guaranteed way to be able to move
from one platform to another and have it all still work.

something else to keep in mind -- always use a global variable for your
local file path root.  windows uses a drive as the ultimate root while unix
uses a slash.  being able to change this in one location is crucial to
portability.  you might also want to do this for your relative mappings as
well, if you use them, since you might not be able to setup the same mapping
in the new location.

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list