It seems that my $pdo is out of scope for some reason because it returns null but when I move the function code block outside of the function it works.
db.php
<?php
$host = 'localhost';
$db = 'phpcms';
$user = 'root';
$pass = 'root';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
    PDO::ATTR_ERRMODE       =>  PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE    =>  PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES      =>  false,  
];
$pdo = new PDO($dsn, $user, $pass, $opt);
functions.php
<?php require_once("include/db.php"); ?>
<?php require_once("include/sessions.php"); ?>
<?php  
    function redirect_to($New_Location)
    {
        header("location:".$New_Location);
        exit();
    }
    function login_Attempt($Username, $Password)
    {
        $Query = $pdo->prepare('SELECT * FROM registration WHERE username=? AND password=?');
        $Query ->execute([$username, $password]);
        if($admin = $Query -> fetch())
        {
            $_SESSION['User_Id']=$admin['id'];
            $_SESSION['Username']=$admin['username'];
            $_SESSION['SuccessMessage']="Welcome Back, {$_SESSION['Username']}";
            redirect_to("dashboard.php");
        }
        else{
            $_SESSION['ErrorMessage']="Incorrect Username and Password Combination!";   
            redirect_to("login.php");           
        }
    }
?>
login.php
<?php require_once("include/db.php"); ?>
<?php require_once("include/sessions.php"); ?>
<?php require_once("include/functions.php"); ?>
<?php  
    if(isset($_POST['Submit'])){
        $username               =   $_POST['Username'];
        $password               =   $_POST['Password'];
        if(empty($username) || empty($password))
        {
            $_SESSION['ErrorMessage']="All fields must be filled out!";
        } 
        else 
        {
            $user = login_Attempt($username, $password);
            //$Query = $pdo->prepare('SELECT * FROM registration WHERE username=? AND password=?');
            //$Query ->execute([$username, $password]);
            //if($admin=$Query -> fetch())
            //{
            //  $_SESSION['User_Id']=$admin['id'];
            //  $_SESSION['Username']=$admin['username'];
            //  $_SESSION['SuccessMessage']="Welcome Back, {$_SESSION['Username']}";
            //  redirect_to("dashboard.php");
            //}
            //else{
            //  $_SESSION['ErrorMessage']="Incorrect Username and Password Combination!";               
            //}
        }
    }
?>
If I remove the commented out code everything works, but when I try to use the login_Attempt function it gives the error "Call to a member function prepare() on null". It doesn't matter where the login_Attempt function is declared, I tried in the functions.php first then I tried moving the method to login.php but still had the same error.
Since the db.php is inserted first, shouldn't the functions.php be inside the pdo's scope?
