Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

resetting the value of a constant

Status
Not open for further replies.

hmerrill

Programmer
Dec 4, 2000
473
US
mysql 3.23.28 gamma
PHP 4.0b4pl1
Apache 1.3.12

I need to change the value of a constant

from: define("DB_SERVER","localhost");
to: define("DB_SERVER","new_host");

I've made the change, but can't get PHP to recognize the new value. How do I get PHP to recognize the new value? Since I have PHP compiled into Apache, I restarted Apache, but still PHP is seeing the old value of DB_SERVER.

TIA.
Hardy Merrill
Mission Critical Linux, Inc.
 
Im not totally sure what you are trying to do, but I can see that you are trying to change over from a mysql database hosted on localhost to a database somewhere else.

This can be handled from within a php script itself. When you connect to a database from within php you specify the database location and details:

$db = mysql_connect("host", "username", "password");

mysql_select_db(database_name, $db);


$db is now the database pointer on which to carry out mysql queries.

The other alternative is to edit the php.ini file itself, which changes the start up configuration of php. (you will need to restart apache after doing this)

find your php.ini file
(on a linux machine logon as super user then type:
cd / #(change to root directory)
find -name php.ini #(search for php ini file)
pico php.ini #(edit the file)
vi php.ini #(or try this one if you dont have pico text editor installed)

find the mysql section within the php.ini file, where you can edit the default hostname details. save the file and restart apache webserver.

hope that helps....



Andres Jugnarain
Wireless Editor
 
I'm still haven't solved this PHP constants problem - I'm not able to reset the value of a constant, and have PHP scripts recognize the new value of the constant.

My setup is like this:

/docroot/test - php scripts
/docroot/test/includes - include files
/doc/root/test/includes/site.def - contains
was: define("DB_SERVER","localhost");
now: define("DB_SERVER","new_host");

/docroot/test/first.php
---------------
at the top of first.php are these includes

include("includes/site.def");
include("includes/common.inc");

common.inc contains function "abc" which references constant DB_SERVER - a print at the top of "abc" shows that DB_SERVER still contains the old value.

I've checked the php.ini file for the mysql defaults - all the mysql defaults are set to nothing - so PHP is not getting "localhost" from the mysql defaults.

What am I doing wrong, or not doing right?
Hardy Merrill
Mission Critical Linux, Inc.
 
Found the problem - turns out in our php.ini we set the auto_prepend_file to a php script, and one of the things that that php script does is to "include" a file that sets the same constant DB_SERVER. So since the DB_SERVER is already set by the auto_prepend_file, setting the same constant in my script to a different value has no effect since a constant cannot be reset during a script's execution. All I did was to rename my constant to another name that does not overlap any other constant's name.

Hope this saves someone some time - certainly cost me some time ;-)
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top