How can one properly handle string arguments in PHP functions like mysql_connect()?

When handling string arguments in PHP functions like mysql_connect(), it is important to properly escape and sanitize the input to prevent SQL injection attacks. One way to do this is by using the mysqli_real_escape_string() function to escape special characters in the string before passing it to the function. This helps to ensure that the input is safe to use in the SQL query.

// Example of properly handling string arguments in mysql_connect()

// Establish a connection to the MySQL database
$servername = "localhost";
$username = "root";
$password = "";
$database = "mydatabase";

// Create a connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";