Variable gets overwritten somewhere?

    Date: 02/05/06 (PHP Community)    Keywords: php, mysql, database, sql, apache

    FIXED. Thanks to '[info]'hipmaestro -- I downloaded PHP 4.3.11 and upgraded my installation, and it's fixed. :)

    I've been working at this since last night -- and I'm quite clueless about what's happening. I was thinking that it could possibly be that my system has been working too long and there are weird memory leaks (yes, I have no more good ideas) so I thought I'd just go back in the morning... but now it's morning and the error is still there. The error is-- at some point of the script, a certain variable gets overwritten with the text of the next variable.

    This is how the script is set up: there is a config file that's included all over the place -- in all the visible pages and in each function (I'm toying with the idea of using constants instead, but for now this is what I'm using). The config file has the database variables, and along the top I define the connection stuff:

    $db_server = 'localhost';
    $db_user = 'username';
    $db_password = 'password';
    $db_database = 'databasename';

    So I include it in almost everywhere. The script's functions is included in a mod_modulename.php file, such as get_this_stuff(); and add_something(); and so on and so forth. For the script I'm using, some user settings are stored in the database, and I have a mod_settings.php file with the following functions:

    • get_setting( $settingshortname );
    • get_setting_title( $settingshortname );
    • get_setting_desc( $settingshortname );
    • update_setting( $settingshortname, $newvalue );
    • ...

    There are a few other functions but those are the ones needed to, er, get the gist of the way they're set up.

    So now I'm working pretty well, until I come to one page and at the bottom of the page, I get a MySQL error about not being able to connect to the test database. See this (before?) screenshot. I fiddle around, check config, etc etc. Nothing. I look for where the database connect is failing, and it's in get_setting( ... ); so I go there and take a look. I add a few echoes in there, to check my config values and look what happens to the page: whatthehell?

    I've searched the whole script directory and the ONLY place where I assign a value to $db_user is in config.php; nowhere else. I don't have register_globals turned on, and I don't plan to ever turn it on; and I've checked the $_* arrays, and there is no index of that name. I ended up going to config.php and doing a series of echoes, and did this:

    echo '$db_user is now: ' . $db_user . '

    ';
    $db_server = 'localhost';
    $db_user = 'username';
    $db_password = 'password';
    $db_database = 'databasename';
    echo '$db_user is now: ' . $db_user . '

    ';


    And that results to this:

    Notice: Undefined variable: db_user in D:\Site\devt\Enth3\enth3\config.php on line 11
    $db_user is now:

    $db_user is now: password

    *tears hair out!* It's right before the line and it assigns $db_password. I have no idea what's going on. I commented out the $db_server line and the $db_user line got 'username' as its value. I repeated $db_user twice consecutively, still 'password'. I repeated $db_user twice, the next one after $db_password, and it works. Here's another: I switched the $db_password and $db_database variables, which means $db_database now goes before $db_password. The value of $db_user? It's 'database'. NOT 'databasename', but 'database'. WHAT THE HELL IS GOING ON.

    I suppose I could make a fix where $db_user goes after $db_password or something, but just the fact that this is happening means that there's just plain something wrong with what's happening, either with the interpreter or my code or... whatever. I don't see what's wrong, and I've exhausted all possible ideas in my head as to what's wrong... can anyone help me?

    If it might be useful -- the PHP interpreter died on me twice yesterday. I'm not sure why. It just did. Windows XP (SP2) just told me that the PHP interpreter got some errors or something (I forgot what it said) and needs to close. I let it close, I rebooted the computer, and went on. I'm working with Apache 2.0 and PHP 4.3.0 and MySQL 4.0.15 on this machine, which is on Pentium4 2.4 GHz and 480MB memory (512, but the rest is being eaten up by the video card).

    Any ideas? Help? Suggestions?

    Source: http://community.livejournal.com/php/407728.html

« Echo the name of a variable? || SQL/PHP question »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home