How to Prevent SQL Injection in Go

Prevent SQL injection in Go by using parameterized queries with placeholders instead of string concatenation.

Prevent SQL injection in Go by using parameterized queries with placeholders instead of string concatenation. Never interpolate user input directly into SQL strings.

// Safe: Use '?' placeholders and pass values as arguments
row := db.QueryRow("SELECT name FROM users WHERE id = ?", userID)
var name string
err := row.Scan(&name)

This approach ensures the database driver treats input as data, not executable code.