I am trying to fetch a bunch of values entered by the user using mysql like operator
In my get route in Nodejs I have
console.log(req.query.key)
pool.query("select FirstName from users where FirstName like %'" + req.query.key +"%'"
In my debug console I get
dav
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 '%'dav%'
I just ran this query in mysql workbench and it is working properly over there
select FirstName from users where FirstName like '%dav%'
MySQL Workbench returns
David
I am not sure why I get the error in Nodejs
Edit 1:
I am using the `mysql` package
app.js
const mysql= require('mysql');
const pool = mysql.createPool({
connectionLimit : 10,
host: keys.connection.host,
user: keys.connection.user,
password:keys.connection.password,
database:keys.connection.database,
})
I am sure there is not issues with my connection because my other routes are working properly without error