Tjk Posted August 26, 2007 Share Posted August 26, 2007 I wanted an opinion on this. I have created a text based game which requires multiple attributes to be used in the scripts. My question is whether or not it would be better just to pull all the data at the top of each page and store it in multi-dimensional arrays for example.... array(name of user array(data of user)) and then access this using array[user][data] or to use mysql queries throughout the script to select specific row data? Opinions appreciated Quote Link to comment Share on other sites More sharing options...
448191 Posted August 26, 2007 Share Posted August 26, 2007 Deciding how much to pull from a database is a zen art in it's own right. You'll need to find balance between limiting the number of queries and loading unnecessary data. If you think you might need it, and you can pull it with the same query, do so, unless that means allocating large quantities of memory. If you can save yourself a trip to the database, you should always seriously consider doing so, even if it is not absolutely certain you will need the data. Quote Link to comment Share on other sites More sharing options...
ReDucTor Posted August 26, 2007 Share Posted August 26, 2007 <?php class Users implements ArrayObject { function offsetGet($index) { $q = mysql_query('SELECT * FROM users WHERE username=\''.addslashes($index).'\''); if(mysql_num_rows($q)) return mysql_fetch_assoc($q); } } $users = new Users(); var_dump($users['myusername']); ?> http://www.php.net/spl Look at the ArrayObject. Quote Link to comment Share on other sites More sharing options...
448191 Posted August 26, 2007 Share Posted August 26, 2007 No offence, but that's not a very smart way to handle persistent data. Every time you need data it makes a trip to the database. And ArrayObject is a class, not an interface! Quote Link to comment 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.