Categories
Sql like golang?
How to write a record like this safely:q = "%first page%"
q = "%first page%"
db.Query("SELECT * FROM `page` WHERE `title` LIKE ?", q)
db.Query("SELECT * FROM `page` WHERE `title` LIKE '%?%'", q)
Answer the question
In order to leave comments, you need to log in
The % signs must be in the data. Therefore, either on the application side add % around the edges of the line Or on the sql side you collect:
db.Query("SELECT * FROM `page` WHERE `title` LIKE concat('%', ?, '%')", q)
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question