Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

resetting the value of a constant

resetting the value of a constant

resetting the value of a constant

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.


Hardy Merrill
Mission Critical Linux, Inc.

RE: resetting the value of a constant

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

RE: resetting the value of a constant

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");

  at the top of first.php are these includes


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.

RE: resetting the value of a constant

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close