What are the potential security risks associated with using deprecated functions like mysql_query in PHP for database interactions?

Using deprecated functions like mysql_query in PHP for database interactions can pose security risks such as SQL injection attacks. It is recommended to use parameterized queries or prepared statements to prevent SQL injection vulnerabilities. By using these modern techniques, you can securely interact with your database without exposing it to potential threats.

// Connect to database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Prepare a statement
$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");

// Bind parameters
$stmt->bind_param("s", $username);

// Execute the statement
$stmt->execute();

// Get the result
$result = $stmt->get_result();

// Fetch data
while ($row = $result->fetch_assoc()) {
    // Process the data
}

// Close the statement and connection
$stmt->close();
$mysqli->close();