Ok so I did a search to see if there other posts that explain this completely...
Well i'm here now :)
SCENARIO:
You'll need PHP to make connection inside connection.php file
<?php
$conn= mysqli_connect("localhost","ID","Password","Database_name");
Then in each file you put require('connection.php');
and there is no way than that for making a connection to MySQL database.
Set queries as functions and send the thing you want to search for as a variable.
Use $_Session or $_Cookie once the user enter his email/password.