문제

SELECT * FROM table WHERE sid=$steering_committee AND project_num = REGEX '/^$qmonth/'");

project_num is an 11 char string with the month being the first 2 chars. I want to filter based on the $month passed from form input and display.

I've also tried this:

SELECT * FROM table WHERE sid=$steering_committee AND project_num = REGEXP '^[" . $qmonth . "]'");

doesn't like syntax on this either

올바른 솔루션이 없습니다

다른 팁

Why not SUBSTRING()? I think it would be faster anyway:

SUBSTRING(project_num, 1, 2) = '$qmonth'

Try this instead:

SELECT * FROM table WHERE sid=$steering_committee AND project_num REGEXP '^$qmonth'

Then ask your self a few questions.

Should I be using prepared statements instead of variable interpolation? Or, do I just like being hacked?

Should I really be using a REGEXP, which can never be indexed, or would a very indexable prefix match work just as well "AND project_num LIKE '$qmonth%'"? Or do you really dislike snappy web pages?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top