title: PHP MySQL Different results between query on web server and phpmyadmin
body: <p>I have a field that looks like this:</p>
  
  <blockquote>
    <p>Intelligence: 0/75</p>
  </blockquote>
  
  <p>I have a form that users can search the value of this string. On my live web server, this is the query:</p>
  
  <pre><code>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-&gt;bindValue(':var2', $var2);
  </code></pre>
  
  <p><code>:var2</code> is the $_POST value. I've been using the case of <code>4</code>. This is the literal regexp when 4 is plugged in:</p>
  
  <pre><code>Intelligence(: | : )([4-9]|[0-9]{2,3})[ ]{0,1}/[ ]{0,1}([4-9]|[0-9]{1,3})
  </code></pre>
  
  <p>Since the field in my database is <code>Intelligence: 0/75</code> this query shouldn't yield any results. But it does, on my live web server. It returns the field <code>Intelligence: 0/75</code>.</p>
  
  <p>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:</p>
  
  <pre><code>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})' )
  </code></pre>
  
  <p>Can anyone see why the hell this is yielding two diff. results?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I think I've narrowed it down to the PHP. If I change the value being bound to <code>:var2</code>, to like</p>
  
  <pre><code>$stmt-&gt;bindValue(':var2', '6284');
  </code></pre>
  
  <p>The results are the same. All rows with <code>Intelligence: 0/75</code> are returned.</p>
  
  <p>If I delete the <code>bindValue</code> code, so there is nothing being bound to :var2, the results are still the same!</p>
  
  <p>print_r($stmt) = </p>
  
  <pre><code>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}))')
  </code></pre>