Часть решения проблемы включала помещение функции IF внутри оператора select.Кроме того, замена ИЛИ на «И» помогла исключить возвращение всей базы данных поля города или названия школы, если оно оставлено пустым.
$sql = "select * from epic_schools_tbl where country = if(length(:countryname)=0, country, :countryname2) and city = if(length(:cityname)=0, city, :cityname2) and (school_name like concat('%', if(length(:schoolname)=0, school_name, :schoolname2) , '%') or alternate_names like concat('%', if(length(:alternatenames)=0, alternate_names, :alternatenames2) , '%') and aka_names like concat('%', if(length(:akanames)=0, aka_names, :akanames2) , '%'))";
$stmt = $pdo->prepare($sql);
$countryname = $_POST['country'];
$cityname = $_POST['cityname'];
$schoolname = $_POST['schoolname'];
$alternatenames = $_POST['schoolname'];
$akanames = $_POST['schoolname'];
//Bind the variables to the prepared statement. Maybe each bind variable must have unique name.
$stmt->bindParam(':countryname', $countryname);
$stmt->bindParam(':countryname2', $countryname);
$stmt->bindParam(':cityname', $cityname);
$stmt->bindParam(':cityname2', $cityname);
$stmt->bindParam(':schoolname', $schoolname);
$stmt->bindParam(':schoolname2', $schoolname);
$stmt->bindParam(':alternatenames', $alternatenames);
$stmt->bindParam(':alternatenames2', $alternatenames);
$stmt->bindParam(':akanames', $akanames);
$stmt->bindParam(':akanames2', $akanames);
//Nothing to pass in. Everything is already bound.
$stmt->execute();