Are there any best practices for synchronizing user registration between a website and a forum in PHP?

When synchronizing user registration between a website and a forum in PHP, it is important to ensure that the user's information is consistent across both platforms. One way to achieve this is by creating a centralized user database that both the website and forum can access. When a user registers on the website, their information should be added to the database, and the forum should be able to retrieve this information when the user logs in.

// Assuming $websiteUser contains the user information from the website registration
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Insert user information into the centralized database
$sql = "INSERT INTO users (username, email, password) VALUES ('$websiteUser['username']', '$websiteUser['email']', '$websiteUser['password']')";
$conn->query($sql);

// Close the database connection
$conn->close();