Jump to content

Read Variables From MYSQL Table


sogorman

Recommended Posts

I am working on a simple web app in which I want to store about 20 variables in a MYSQL table so when I hand off the project the variables can be easily edited by the end user. Is it easy to store variables in a MYSQL table then query those and make them PHP variables? Really I just need to read a MYSQL table and pull two columns; AppOption and AppOptionValue then create PHP variables for each of the results making the AppOption the variable name and the AppOptionValue the value of said varible.

 

Any Ideas?

 

Thanks!

 

Sean

 

Link to comment
Share on other sites

Does the end user have any kind of technical knowledge? Even a little bit?

 

In other words, what if you gave them a file like

/********************
* Database options *
********************/

// the location of the MySQL server
// ex: localhost, mysql.example.com, 127.0.0.1
$db_host = "localhost";

// the MySQL user
// ex: dbuser
$db_user = "dbuser";

// the MySQL user's password. leave blank for none
// ex: dbpassword
$db_pass = "";

// the MySQL database
// ex: myapp
$db_db = "myapp";

/******************
* Upload options *
******************/

// upload directory URL
// ex: /uploads
$upload_dir = "/uploads";

// allowed upload file types. use file extensions
// ex: jpg;jpeg;png;gif
$upload_ext = "jpg;jpeg;png;gif";

Link to comment
Share on other sites

For safe you could use XML or INI or another simple file format.

 

If you really want it in the database then you can use variable variables. After checking that the option is valid.

name       | value
-----------+------
db_host    | localhost
db_user    | dbuser
db_pass    |
db_db      | myapp
upload_dir | /uploads
upload_ext | jpg;jpeg;png;gif

$options = array(
// database
"db_host", "db_user", "db_pass", "db_db",
// uploads
"upload_dir", "upload_ext"
);

// for each $row in the table {
if (in_array($row["name"], $options)) {
	${$row["name"]} = $row["value"];
}
// }

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.