In the context of PHP development, what are the implications of using string variables in SQL queries for database searches and updates?

When using string variables in SQL queries for database searches and updates, it is important to sanitize the input to prevent SQL injection attacks. This can be done by using prepared statements and parameterized queries, which help separate the SQL code from the user input.

// Example of using prepared statements to prevent SQL injection
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Prepare a SQL query with a placeholder for the string variable
$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);

// Set the value of the string variable and execute the query
$username = "john_doe";
$stmt->execute();

// Process the results
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    // Do something with the data
}

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