I have a field that looks like this:
Intelligence: 0/75
I have a form that users can search the value of this string. On my live web server, this is the query:
SELECT * FROM `test` WHERE `id` IS NOT NULL AND `file` REGEXP CONCAT('Intelligence(: | : )([', :var2, '-9]|[0-9]{2,3})[ ]{0,1}/[ ]{0,1}([', :var2, '-9]|[0-9]{1,3})')
$var2 = $_POST['int'];
$stmt->bindValue(':var2', $var2);
:var2 is the $_POST value. I've been using the case of 4. This is the literal regexp when 4 is plugged in:
Intelligence(: | : )([4-9]|[0-9]{2,3})[ ]{0,1}/[ ]{0,1}([4-9]|[0-9]{1,3})
Since the field in my database is Intelligence: 0/75 this query shouldn't yield any results. But it does, on my live web server. It returns the field Intelligence: 0/75.
If I go and run this EXACT query in phpmyadmin, I get no results. I've lined up the query from phpmyadmin and my server in my text editor and they're identical. Just so I'm not crazy, here's the query copy/pasted from phpmyadmin:
SELECT *
FROM `test`
WHERE `id` IS NOT NULL
AND `file`
REGEXP CONCAT( 'Intelligence(: | : )([4-9]|[0-9]{2,3})[ ]{0,1}/[ ]{0,1}([4-9]|[0-9]{1,3})' )
Can anyone see why the hell this is yielding two diff. results?
Update:
I think I've narrowed it down to the PHP. If I change the value being bound to :var2, to like
$stmt->bindValue(':var2', '6284');
The results are the same. All rows with Intelligence: 0/75 are returned.
If I delete the bindValue code, so there is nothing being bound to :var2, the results are still the same!
print_r($stmt) =
SELECT * FROM `test` WHERE `id` IS NOT NULL AND `file` REGEXP
CONCAT('(INT:[ ]{1,2}([', :var2, '-9]|[0-9]{2,3})[ ]{1,2}/[ ]{1,2}([', :var2, '-9]|[0-9]{1,3})|Intelligence(: | : )([', :var2, '-9]|[0-9]{2,3})[ ]{0,1}/[ ]{0,1}([', :var2, '-9]|[0-9]{1,3}))')
$stmt->bindValue(':var2', $var2);where is var2 in the query you gave us?