Jump to content

php connect to mysql database (complicated problem... help??)


obay

Recommended Posts

im not sure this is the right place to ask, if it's not, please refer me to another forum.. anyway, here goes..

 

i have a php application, with a database having a table "settings" with two columns, "field" and "value":

 

settings.php: //code to extract the settings from the database into $settings

$settings = array ();
$settings_query = mysql_query("SELECT * FROM settings"); //settings include the database hostname, uname, pw, etc
while ($setting = mysql_fetch_array($settings_query)) {
$settings[$setting[field]] = $setting[value];
}

 

what im trying to do is save application settings (including the database hostname, username, password, etc) into the database, through the table "settings". so now you know my problem is that i can't connect to the database in order to get the database connect info because in the first place i don't have the database connect info to connect to the database.. ( stupid problem right? :( )

 

currently the settings are saved in a .php file(as php variables) but the reason i want to save them in a database is because i have a editSettings.html file - which has an html form for easy editing of the settings (doesn't have to be done by editing php code manually), and saves the changes into the database.

 

this is not actually a question, but i'm asking for any suggestions. any help appreciated...

while ($setting = mysql_fetch_array($settings_query)) {
$settings[$setting[field]] = $setting[value];
}

 

change that line to...

while ($setting = mysql_fetch_array($settings_query)) {
foreach($setting as $key => $val)
{
  $settings[$$key][] = $val;
}
}

 

seems pointless saving database connection details in a database where you need those details to access it anyway....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.