What potential issue might arise when using the mysql_error() function in PHP?

Using the mysql_error() function in PHP can potentially expose sensitive information about your database structure or queries to users if an error occurs. To solve this issue, it is recommended to avoid displaying detailed error messages directly to users and instead log the errors for the developers to review.

// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    // Log the error instead of displaying it to the user
    error_log("Connection failed: " . mysqli_connect_error());
    // Display a generic error message to the user
    echo "An error occurred. Please try again later.";
}