I have a prepare and a query function in go and when I place the ? in the search it works fine. When I try and do a contains search with the % I get sql: statement expects 0 inputs; got 1
How can I do this type of query without having the variables directly in the SQL? I want to prevent SQL injection . Thank You for your help.
I am using go version go1.8.1 darwin/amd64 and using MySQL
My Go Code:
stmt, err := dBusers.Prepare("SELECT id, name, email, username FROM users WHERE name LIKE '%?%';")
if err != nil {
logging.LogError("Could Not Query All Users: "+err.Error())
return nil, errors.New("Could Not Query Users")
}
rows, err := stmt.Query(name)