NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP Question -- SID in Oracle

Gary Mort bz-gmort at beezifies.com
Tue Dec 4 10:59:32 EST 2007


Julia Sheehy wrote:
> *Gary Mort* bz-gmort at beezifies.com 
> <mailto:talk%40lists.nyphp.org?Subject=%5Bnyphp-talk%5D%20PHP%20Question%20--%20SID%20in%20Oracle&In-Reply-To=475553B7.70303%40vassar.edu> 
>
>
> Dear Gary,
>
> Yes.  I can  set the database name while making the connection. I use 
> an include file for the connection and make a small change just  to 
> the name of the SID when I want to point the whole shebang to the 
> production data.
>
> My problem is that the SID name I return in using getenv is wrong.

I guess the question I was driving out is what /sets/ the getenv 
variable to begin with.

 From glancing through the docs, I didn't see that mentioned.  Generall, 
an environmental variable is set by the server prior to the script even 
being executed.  In which case, that SID is really just your server 
setup being "helpful" and expecting you to use the environmental 
variable in your connection statement.

It doesn't actually mean or represent anything beyond what Oracle 
connection information the server thinks most PHP scripts run on it 
would want to use.

In short, the SID is a broken clock, it will be right twice a day(when 
your using the database the server is configured to use) but otherwise 
it is useless information for you.

Instead, I'd build up the connection string in a more procedural manner, 
such as:

define('DB_NAME' , 'testserverX');
define('DB_SERVER' , 'somemachinehere.vassar.edu');
define('DB_PORT' , 'XXXX');
define('DB_CONNECTION' , '(DESCRIPTION =

                   (ADDRESS = (PROTOCOL = TCP)(HOST = '. DB_SERVER . 
')(PORT = '.DB_PORT.'))
                   (CONNECT_DATA = (SID ='.DB_NAME.' )))');
So if you want to display something conditional in the program, for example:
if (DB_NAME == 'testserverX') {
echo "<font color='red'><h2>You are using the test server, updates will 
not affect live data!</h2></font>";
}

Than you can(and yes, 'proper' formatting of the above would be to use 
CSS to define the text size and text color rather than embedding ugly 
old h2 and font tags.  I'm just too lazy to write out all the styling in 
an email message.)



More information about the talk mailing list