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...

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.