tags:

views:

52

answers:

2

When I create a database on my hostgator webserver, it prepends a database prefix to the database name. for instance if I do

CREATE DATABASE 'dbname'

it makes a db called myname_dbname

My question is, is there a way I can have my PHP get the db prefix so that I can add it into my configuration file?

A: 

Why not hard code the prefix? Would that be such a bad thing? Or set up your config to detect the hosting environment and add the prefix only in this situation.

I'd say you could use DESCRIBE to get information about the Db, but I am guessing it is s shared host and your ability to use statements like DESCRIBE might be limited.

jakenoble
well basically the code I'm writing is for distribution and I want other people to be able to install it as well. The installation creates the db, tables, and writes the data out to a config files.
d-c
+2  A: 

The prefix value is usually your login name. On shell you can find it using

echo $LOGNAME

In PHP you can use getenv as:

$DB_prefix = getenv('LOGNAME');
codaddict
Ah, nice. Didn't know that was often the case.
jakenoble