title: MySQL - Getting Two Different Results (PHP and phpMyAdmin)
body: <p>I'm trying to run a SQL query, and it is working correctly in phpMyAdmin, but whe running it in PHP, the query comes back very wonky. The following query yields two different results:</p>
  
  <pre><code>SELECT `stock_ticker`, `stock_simpleName`, `stock_logo` 
  FROM `stocks` 
  WHERE stock_simpleName REGEXP'^c'
  </code></pre>
  
  <p>I get the following results in phpMyAdmin (Which is correct):</p>
  
  <pre><code>stock_simpleName
  ----------------------
  Coca-Cola
  Campbell's
  ConAgra Foods
  </code></pre>
  
  <p>However, in PHP it comes out really weird:</p>
  
  <pre><code>stock_simpleName
  -----------------------
  Coca-Cola
  MasterCard
  Campbell's
  Microsoft
  The Walt Disney Company
  PepsiCo
  The Hershey Company
  Proctor &amp; Gamble
  ConAgra Foods
  ...etc...
  </code></pre>
  
  <p>Why is this happening? This doesn't make any sense. Is it due to a server setting in PHP or some form of encoding or whatnot?</p>
  
  <hr>
  
  <h2>EDIT:</h2>
  
  <p>Here is my PHP Code:</p>
  
  <p>The sub-model class (the creator of the pieces):</p>
  
  <pre><code>public function allOtherSearchResults($query, $dontQuery = null) {
  
      $name = "stocks";
      $where = "stock_simpleName REGEXP'^" . $query . "'";
      $cols = array("stock_ticker", "stock_simpleName", "stock_logo");
      $limit = 5;
  
      return $this-&gt;select($name, $cols, $where, $limit);
  
  }
  </code></pre>
  
  <p>The main-model class (this runs the query):</p>
  
  <pre><code>public function select($tableName, $columns, $where = null, $limit = null) {
  
      global $purifier;
  
      // Make columns SQL friendly
      $cols = "`";
      $cols .= implode("`, `", $columns);
      $cols .= "`";
  
      $table = "`" . $tableName . "`";
  
      if (!empty($where)) {
  
          $where = " WHERE " . $where;
  
      }
  
      // Check limit
      if (!empty($limit)) {
  
          $limit = " LIMIT $limit";
  
      }
  
      // SQL CODE
      $sql = "SELECT " . $cols . " FROM " . $table . $where . $limit;
  
      // SQL DEBUGGING IF CODE RETURNS BOOLEAN ERROR
      echo $sql . "&lt;br&gt;";
  
      $query = $this-&gt;conn-&gt;query($sql);
  
      // Store the value in a variable called table with an array of that table's name followed by it's values
      // EX: $model-&gt;table["bands"]["band_name"]
      //
      // Accessible by the individual page/directory's controller's
  
      while($row = $query-&gt;fetch_assoc()){
  
          // Store values as $model-&gt;table["tableName"]["columnName"]["index (usually 0)"]
          foreach ($row as $key =&gt; $val) {
              $this-&gt;data[$tableName][$key][] = $row[$key];
          }
  
      }
  
  
      // Loop through results to clean them
      // Foreach loops through each column
      // Make sure the table isn't empty (i.e. login returns an error)
      if (!empty($this-&gt;data[$tableName])) {
          foreach ($this-&gt;data[$tableName] as $key =&gt; $tableArray) {
  
              // For loop goes through each value in a certain row
              for ($i = 0; $i &lt; count($tableArray); $i++) {
                  // Convert from data variable to table after HTML PURIFIER
                  $this-&gt;table[$tableName][$key][$i] = $purifier-&gt;purify($tableArray[$i]);
              }
  
          }
      }
  
  
      // Declare the array after loop has finished for use in view
      $this-&gt;table;
  
      if (!empty($this-&gt;table)) {
  
          return true;
  
      }
  
  }
  </code></pre>
  
  <p>And it gives me the same SQL output as above. I am not sure if there is a different interpretation of certain characters in PHP versus the standard MySQL in phpMyAdmin. Has anyone even had this problem before?</p>