unkwntech Posted August 25, 2008 Share Posted August 25, 2008 What is the quickest way to get a large amount of data (think golf) and the most efficient (think performance) to get a large amount of data from a MySQL database to a session without having to continue doing what I already have: $sql = "SELECT * FROM users WHERE username='" . mysql_escape_string($_POST['username']) . "' AND password='" . mysql_escape_string(md5($_POST['password'])) . "'"; $result = mysql_query($sql, $link) or die("There was an error while trying to get your information.\n<!--\n" . mysql_error($link) . "\n-->"); if(mysql_num_rows($result) < 1) { $_SESSION['username'] = $_POST['username']; redirect('index.php?p=signup'); } $_SESSION['id'] = mysql_result($result, '0', 'id'); $_SESSION['fName'] = mysql_result($result, '0', 'fName'); $_SESSION['lName'] = mysql_result($result, '0', 'lName'); ... And before anyone asks yes I do really need to 'SELECT *' Yes, I am sanitizing the data, so that there can be no SQL injection, that is further up in the code. Quote Link to comment https://forums.phpfreaks.com/topic/121208-solved-database-session/ Share on other sites More sharing options...
Fadion Posted August 25, 2008 Share Posted August 25, 2008 I would think treating the session as an array. You will have only one array variable (in contrast to a lot of different variables) and better performance (i think) as you're creating and manipulating just one array. Quote Link to comment https://forums.phpfreaks.com/topic/121208-solved-database-session/#findComment-624819 Share on other sites More sharing options...
Mchl Posted August 25, 2008 Share Posted August 25, 2008 I usually go like this: $row = mysql_fetch_array($result); foreach ($row as $key => $value) { $_SESSION[$key] = $value; } Quote Link to comment https://forums.phpfreaks.com/topic/121208-solved-database-session/#findComment-624822 Share on other sites More sharing options...
unkwntech Posted August 25, 2008 Author Share Posted August 25, 2008 I found this and went with it, but thanks anyway. while($row = mysql_fetch_assoc($result)) { $_SESSION = array_merge_recursive($_SESSION, $row); } Quote Link to comment https://forums.phpfreaks.com/topic/121208-solved-database-session/#findComment-624823 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.