nodejs通过准备好的语句引发类似mysql的查询错误 [英] nodejs throws error with mysql like query via prepared statements

查看:39
本文介绍了nodejs通过准备好的语句引发类似mysql的查询错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 nodejs 从数据库中检索值.我通过准备好的语句实现了类似 mysql 的查询,以确保消除 sql 注入攻击.我的问题是它没有检索到任何结果.它只是在控制台中显示空结果请有人指出我查询有什么问题

Am retrieving values from database using nodejs. I implemented mysql like query via prepared statement to ensure that sql injection attack is eliminated. my problem is that it does not retrieve any result. it just show empty results in the console please can someone point to me what is wrong with the query

exports.autosearch = function (req, res) {
//var search = req.body.searchText;

var search = 'bukatti';
//db.query('SELECT * FROM users WHERE name like ?', ['%' + search + '%'], function (error, results, fields) {


db.query('SELECT * FROM users WHERE name like ?', ['%search%'], function (error, results, fields) {
console.log(results);






});



}

谢谢

推荐答案

我发现了我的问题.我添加了错误日志并发现某处是类型错误.无论如何,这修复它

I have found out my problem. i added the error log and discover that the was type error somewhere. This fix it anyway

db.query("SELECT * FROM users WHERE name like ?", ['%' + search + '%'], function (error, results, fields) {

谢谢

这篇关于nodejs通过准备好的语句引发类似mysql的查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆