I am new to using PDO and was wondering how I would select the logged in user\'s id from my phpMyAdmin database.
My initialization file is...
sessio
I'm assuming you want to get the users info where their id
is the same as user_id
You might do something like this;
$query = $db->prepare('SELECT * FROM table WHERE id=:id');
//using bindParam helps prevent SQL Injection
$query->bindParam(':id', $_SESSION['user_id']);
$query->execute();
//$results is now an associative array with the result
$result = $query->fetch(PDO::FETCH_ASSOC);
I wasn't sure how user_id
is set so I just used bindParam just in case.