我尝试获取包含 SQL 数据库中单词的值。我尝试使用“包含”,但出现错误。我使用 SQL
这是我的代码:
router.post('/busca',isLoggedIn, async (req,res) => {
const {busca} = req.body;
const buscar = Object.values({busca});
const bus = await pool.query('SELECT * FROM links WHERE title CONTAINS ?',[buscar]);
res.render('links/busca',{buscar, bus});
});
我有这个错误:
UnhandledPromiseRejectionWarning: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(title, 'a')' at line 1
最佳答案
您可以使用 LIKE 运算符:
SELECT * FROM links WHERE title LIKE '%word%';
如果有多个单词,请使用and
或or
运算符
SELECT * FROM links WHERE title LIKE '%word%' AND title LIKE '%secondword%';
关于javascript - 我如何获取类似于数据库中字段的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57461949/