0

I am trying to execute that query using mysql2:

const [[questions]] = 
  await db.promise().execute(
    'SELECT * FROM `questions` WHERE `questions`.`topic` LIKE ?', 
    ['%' + text + '%']
  );

but get nothing from database.

Then I tried this:

const [[questions]] = 
  await db.promise().execute(
    "SELECT * FROM `questions` WHERE `questions`.`topic` LIKE '?'",
    ['%' + text + '%']
  );

and still nothing.

How should I make prepared statement here?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Pariah
  • 55
  • 1
  • 5

1 Answers1

0

try this way :

let query = `SELECT * FROM questions WHERE questions.topic LIKE '%${text}%'`;

const data = await db.promise().execute(query);
console.log('data ==>',data);
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71