Store info from DB in _SESSION data
<p>I'm grabbing user data from the database using:</p>

<pre><code>$stmt = $db-&gt;prepare("SELECT usernames FROM login.users WHERE emails = :email");
$stmt-&gt;bindValue(":email", $email);
$stmt-&gt;execute();
</code></pre>

<p>And other fields than usernames (I haven't gotten around to fixing specifically which ones I'll be using).</p>

<p>Since I'm grabbing one user's data, it should return a single row of data. Thus, I can use:</p>

<pre><code>$data = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
</code></pre>

<p>which will give me an associative array in $data. But how do I then transfer that to $_SESSION?</p>

<p><a href="http://stackoverflow.com/questions/7135966/array-copying-in-php">Array copying in PHP</a> gave me the idea to use:</p>

<pre><code>$_SESSION[$index] = $data[$index];
</code></pre>

<p>Or similar, but how would I go about automatically finding what $index was?
I'd really like it if I could change the SELECT statement to include different columns without having to have <code>$_SESSION['columnname'] = $data['columnname']</code> for every single column.</p>
