1. Create connection
    <?php
    	try{
    		$hostname = 'localhost';
    		$dbname = 'employees';
    		$username = 'root';
    		$password = 'mysql';
    		$DBH = new PDO("mysql:host=$hostname; dbname=$dbname; charset=utf8mb4", $username, $password);
    		echo 'Connected';
    	}
    	catch(PDOException $e){
    		echo $e->getMessage();
    	}
    ?>;
    			    
  2. Prepare query and fetch
    <?php
    	try{
    		$stmt = $DBH->prepare("select *from employees where gender = ?");
    		$stmt->bindParam(1, $gen);
    		$gen = 'M';
    		$stmt->execute();
    		while($row = $stmt->fetch())
    		{
    			print_r($row);
    		}
    	}
    	catch(PDOException $e){
    		echo $e->getMessage();
    	}
    ?>