1

Hello y need send variable in my request sql. For searching value in my database

var cent = "search";
con.connect(function (err) {
if (err) throw err;
var sql ="SELECT * FROM cadito.activitys WHERE description like ?";
//Send an array with value(s) to replace the escaped values:
con.query(sql, [%cen%], function (err, result) {
    console.log(global.re = JSON.stringify((result)));
});

});

My problème syntaxe error.

Thank for help me.

My log db_conn.js:20 con.query(sql, [%cent%], function (err, result) { ^

SyntaxError: Unexpected token '%' ?[90m at wrapSafe (internal/modules/cjs/loader.js:979:16)?[39m ?[90m at Module._compile (internal/modules/cjs/loader.js:1027:27)?[39m ?[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)?[39m ?[90m at Module.load (internal/modules/cjs/loader.js:928:32)?[39m ?[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)?[39m ?[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)?[39m ?[90m at internal/main/run_main_module.js:17:47?[39m

0

2 Answers 2

1

Try out to use % inside the sql string and remove it from the params :

var cent = "search";
con.connect(function (err) {
if (err) throw err;
var sql ="SELECT * FROM cadito.activitys WHERE description like %?%";
//Send an array with value(s) to replace the escaped values:
con.query(sql, [cent], function (err, result) {
    console.log(global.re = JSON.stringify((result)));
});

});
Sign up to request clarification or add additional context in comments.

Comments

0

i found another issue in my question just placed % in my request and concaten my variable with %

var cent = "search";
con.connect(function (err) {
if (err) throw err;
var sql ="SELECT * FROM cadito.activitys WHERE description like ?";
//Send an array with value(s) to replace the escaped values:
con.query(sql, ['%'+cent+'%'], function (err, result) {
    console.log(global.re = JSON.stringify((result)));
});

});

working for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.