Page 1 of 1

using database to set global variables

Posted: Thu Oct 17, 2002 10:05 am
by jschoneb
This may be impossible, but if it's not, it would really improve my life if somebody could clue me in.

Situation: I have a single PHP script with functions to display forms for updating various MySQL database tables, and a function to send the relevant commands to the database and insert the data. The "insert" function has to have all the variables from the other functions declared global -- as opposed to if the insert task was in a completely separate script, in which case it would just automatically welcome the little variables with open arms.

If my variables change, however, then I need to remember to fix the globals in the insert function. What a pain! I want to do it automatically, generating the globals from the database itself.

I know how to get the field names from the database, and how to turn them into variable names, so I tried doing that and making a string out of them and writing:

Code: Select all

global $variables_from_database_string;
But that doesn't work.

Is it possible? Any ideas out there?

thanks!

Posted: Thu Oct 17, 2002 2:58 pm
by volka
read http://www.php.net/manual/en/language.v ... riable.php and then try something like
global $$variable_from_database_string;