M
M
ML2017-03-05 22:20:29
MySQL
ML, 2017-03-05 22:20:29

Sql like golang?

How to write a record like this safely:q = "%first page%"

db.Query("SELECT * FROM `page` WHERE `title` LIKE ?", q)

Or is it somehow possible?
db.Query("SELECT * FROM `page` WHERE `title` LIKE '%?%'", q)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2017-03-05
@staffID

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 your question

Ask a Question

731 491 924 answers to any question