// Connect to MySQL server $conn = mysqli_connect("localhost", "username", "password", "database"); // Prepare SQL query $query = "SELECT * FROM users WHERE id = 1"; // Execute query $result = mysqli_query($conn, $query); // Fetch user data $user = mysqli_fetch_assoc($result); // Close database connection mysqli_close($conn); // Output user data echo "Name: " . $user['name'] . "
"; echo "Email: " . $user['email'] . "
";
// Load JSON file $data = file_get_contents('users.json'); // Convert JSON data to PHP array $users = json_decode($data, true); // Get user by ID $user = $users[0]; // Output user data echo "Name: " . $user['name'] . "This example uses the built-in PHP function file_get_contents to load a JSON file containing user data. The json_decode function is used to convert the JSON data to a PHP array. No package libraries are required for this example.
"; echo "Email: " . $user['email'] . "
";