JustinK101 Posted April 9, 2008 Share Posted April 9, 2008 I am currently storing all my applications language, i.e. all button text, body text, etc in MySQL in the form of: key - varchar(255) value - varchar(255) 'first_name' 'First Name' 'error_occured' 'An Error Has Occured. Click Here To Continue...' 'submit' 'Submit!' I want a way to load up all the values from this table ONCE, and store everything persistant, meaning I don't have to query and load it again every page, since the language data will barely change. Then I would like to be able to reference things like: $lang->first_name $lang->submit How do I go about doing this? Thanks. Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/ Share on other sites More sharing options...
p2grace Posted April 9, 2008 Share Posted April 9, 2008 Would sessions work for what you're trying to do? Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/#findComment-512655 Share on other sites More sharing options...
JustinK101 Posted April 9, 2008 Author Share Posted April 9, 2008 I think perhaps, here is what I am thinking, but I am not sure this will work. $language = array(); $sql = "SELECT key, value FROM languages WHERE culture = 'en_us' ORDER BY key ASC"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_object($result)) { array_push($language, $row->key => $row->value); } $_SESSION['language'] = $language; Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/#findComment-512675 Share on other sites More sharing options...
discomatt Posted April 9, 2008 Share Posted April 9, 2008 Databases are best used for dynamic data. Why not store all of this information in a static class or as class constants? This will achieve exactly what you want with no additional code. Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/#findComment-512678 Share on other sites More sharing options...
JustinK101 Posted April 9, 2008 Author Share Posted April 9, 2008 Well technically this data inst static because as I add new features and even translate it, it needs to get updated. I am curious though, how do you mantain classes that are static or constant across multiple pages? Do you simply store them in a session as well? Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/#findComment-512684 Share on other sites More sharing options...
JustinK101 Posted April 9, 2008 Author Share Posted April 9, 2008 Ok bear with me, here is a class I came up with, does it make sense what I am doing? class Language { private lang_array; public function Language() { $this->lang_array = array(); } public function add($k, $v) { $this->lang_array[$k] = $v; } public function get($k) { return ($this->lang_array[$k]); } } Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/#findComment-512696 Share on other sites More sharing options...
JustinK101 Posted April 9, 2008 Author Share Posted April 9, 2008 Here is my final class, I think this should work nicely. class Language { private $lang_array; public function Language($culture) { $this->lang_array = array(); $sql = "SELECT key, value FROM languages WHERE culture = '" . $culture . "' ORDER BY key ASC"; $result = mysql_query($sql) or trigger_error(mysql_error(), E_USER_ERROR); while($row = mysql_fetch_assoc($result)) { add($row['key'], $row['value']); } } public function add($k, $v) { $this->lang_array[$k] = $v; } public function get($k) { return ($this->lang_array[$k]); } public function getArray() { return ($this->lang_array); } } Link to comment https://forums.phpfreaks.com/topic/100263-persistant-mysql-data-across-multiple-pages/#findComment-512706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.