M
M
menyaylo20002021-03-27 23:28:43
MySQL
menyaylo2000, 2021-03-27 23:28:43

Why does the same SQL query return different results in JS and phpMyAdmin?

I have a db. One of the tables stores json arrays with user ids in the form of strings ('[1,2,3]')
When I make such a request through phpMyAdmin's sql console

SELECT * FROM conversations WHERE members REGEXP '(\\[|\,)+(1)(\\]|\,)+'


then the correct result is given (all arrays where there is id 1)
But when I make the same request from the node js server using the npm package mysql2 (2.2.5), then the wrong result is given (generally all arrays)

Request with node js:
pool.execute("SELECT * FROM conversations WHERE members REGEXP '(\\[|\,)+(1)(\\]|\,)+'")


What was it and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-03-27
@Fragster

Maybe it's the lack of escaping characters in a string expression in js https://learn.javascript.ru/string#spetssimvoly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question