Below is my code for running a MySQL query from PHP:
mysqli_connect.php
    <?php
        DEFINE ('DB_USER', [my_username]);
        DEFINE ('DB_PASSWORD', [my_password]);
        DEFINE ('DB_HOST', 'localhost');
    
        $databases = array();
        $db_school = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, 'db_school')
        OR die('Could not connect to MySQL.db_school');
        $databases['db_school'] = $db_school;
    
        $db_family_finance = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, 'db_family_finance')
        OR die('Could not connect to MySQL.db_family_finance');
        $databases['db_family_finance'] = $db_family_finance;
    ?>
get_mysql_data.php
    <?php    
        function query_database($query) {
            require_once('../mysqli_connect.php');
    
            $response = mysqli_query($db_school, $query);
    
            if ($response) {
                echo "ran query!<br>";
            } else {
                echo "couldn't run query!<br>";
            }
        
            return $response;
        }
    
        query_database("SELECT * FROM tests"); //prints out "ran query!"
        query_database("SELECT * FROM tests"); //prints out "couldn't run query!"
    ?>
I am running the same function twice. The first time it returns what I want it to. The second time it doesn't. Why would it do this?
I made a few changes to the code as seen above and I now get this printed to the screen:
ran query!
Notice: Undefined variable: db_school in C:\xampp\htdocs\websites\tutorials\get_mysql_data.php on line 6
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\websites\tutorials\get_mysql_data.php on line 6
couldn't run query!
 
     
    
";` to the `else` I get this error: `Notice: Undefined variable: db_school in C:\xampp\htdocs\websites\tutorials\get_mysql_data.php on line 11 Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\websites\tutorials\get_mysql_data.php on line 11` – ToMakPo Dec 17 '16 at 08:11