What potential pitfalls should be considered when using the CONCAT function in SQL queries in PHP?

When using the CONCAT function in SQL queries in PHP, it is important to be cautious of SQL injection vulnerabilities. If user input is directly concatenated into the SQL query without proper sanitization, it can lead to potential security risks. To mitigate this risk, always use prepared statements with parameterized queries to safely insert user input into the SQL query.

// Example of using prepared statements with parameterized queries to safely concatenate user input in SQL query

// Assuming $conn is the database connection object

// User input
$user_input = $_POST['input'];

// SQL query with prepared statement
$stmt = $conn->prepare("SELECT * FROM table WHERE column = ?");
$stmt->bind_param("s", $user_input);
$stmt->execute();

// Fetch results
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    // Process results
}

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