sogorman Posted April 25, 2011 Share Posted April 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234701-read-variables-from-mysql-table/ Share on other sites More sharing options...
requinix Posted April 25, 2011 Share Posted April 25, 2011 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"; Quote Link to comment https://forums.phpfreaks.com/topic/234701-read-variables-from-mysql-table/#findComment-1206099 Share on other sites More sharing options...
sogorman Posted April 25, 2011 Author Share Posted April 25, 2011 I was more thinking of setting up a page where they could update the table rather then them updating the php code. Thought it would be safer. I just can't seem to figure out how to declare and fill variables from the table data. Quote Link to comment https://forums.phpfreaks.com/topic/234701-read-variables-from-mysql-table/#findComment-1206103 Share on other sites More sharing options...
requinix Posted April 25, 2011 Share Posted April 25, 2011 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"]; } // } Quote Link to comment https://forums.phpfreaks.com/topic/234701-read-variables-from-mysql-table/#findComment-1206120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.