You can include this file in your PHP scripts using the include or require statement
Here's the code that includes the database connection file:
<?php
// Include the database connection file
require_once('db_connect.php');
// Query to retrieve all student information from the "students" table
$student_query = "SELECT * FROM students";
// Query to retrieve all subject information from the "subjects" table
$subject_query = "SELECT * FROM subjects";
// Execute the student query
$student_result = mysqli_query($conn, $student_query);
// Execute the subject query
$subject_result = mysqli_query($conn, $subject_query);
// Store the results in PHP variables
$students = mysqli_fetch_all($student_result, MYSQLI_ASSOC);
$subjects = mysqli_fetch_all($subject_result, MYSQLI_ASSOC);
// Close the database connection
mysqli_close($conn);
?>
Note that the require_once('db_connect.php'); line includes the file containing the database connection code. Make sure to update the file name and path to match the location of your db_connect.php file.
In above two script, we first connect to the database using the mysqli_connect() function. We then execute two separate SQL queries to retrieve all the student information and subject information from their respective tables using the mysqli_query() function. The results of these queries are stored in PHP variables using the mysqli_fetch_all() function.
Finally, we close the database connection using the mysqli_close() function. Note that the database connection details such as host, username, password, and database name may vary depending on your specific configuration.