I'm trying to connect to a MySQL database using PHP (with PDO) but I'm not that familiar with PHP so I'm a little stuck. I'm trying to search one of my databases for all occurrences of $userid and then store the $crn associated with it in an array but I don't really know how to go about that. Here's what I have so far...
$sthandler = $conn->prepare('SELECT userid FROM users WHERE userid=' . $userid);
$sthandler->execute(array('username'));
if($sthandler->rowCount() > 0)
{
// User exists, get user's courses from database and returns array of CRNs
for(int i = 0; i < rowCount; i++)
{
$sthandler = $conn->prepare('SELECT crn FROM usercourses WHERE userid=' . $userid);
$sthandler->execute(array($USER => $crnArray));
}
}