What are the key differences between the old code and the code with prepared statements in terms of security and performance?

The key differences between old code and code with prepared statements in terms of security and performance are: 1. Security: Prepared statements help prevent SQL injection attacks by separating SQL code from user input, making it harder for malicious code to be injected into queries. 2. Performance: Prepared statements can be faster as the database can optimize the execution plan for queries, reducing the overhead of parsing and planning queries each time they are executed.

// Old code vulnerable to SQL injection
$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $query);

// Code with prepared statements
$username = $_POST['username'];
$password = $_POST['password'];

$stmt = $conn->prepare("SELECT * FROM users WHERE username=? AND password=?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();