title: MySQL AES Decrypt Return Values
body: <p>Trying to develop an AES-encrypted database for a client using PHP/MySQL. Inserting encrypted values is working, but having trouble returning usable decrypted values.</p>
  
  <pre><code>public static function auth($username="", $password="") {
      global $database;
      $fields = self::$db_fields;
      array_shift($fields);
      $username = $database-&gt;escape_value($username);
      $password = $database-&gt;escape_value($password);
      $hashed_pwd = sha1($password);
      $join_str = ", '" . AUTH_KEY . "'), AES_DECRYPT(";
  
      $sql  = "SELECT id, AES_DECRYPT(";
      $sql .=  join($join_str, $fields) . ", '" . AUTH_KEY . "') FROM " . self::$table_name. " ";
      $sql .= "WHERE u_name = AES_ENCRYPT('{$username}', '" . AUTH_KEY . "') ";
      $sql .= "AND u_pwd = AES_ENCRYPT('{$hashed_pwd}', '" . AUTH_KEY . "') ";
      $sql .= "LIMIT 1";
  </code></pre>
  
  <p>With the following query:</p>
  
  <pre><code>    $query_result = $database-&gt;query($sql);
      $result_array = $database-&gt;fetch_array($query_result);
  </code></pre>
  
  <p>}</p>
  
  <p>Returns:</p>
  
  <pre><code>    Array ( 
          [0] =&gt; 5 
          [id] =&gt; 5 
          [1] =&gt; a_user_name 
          [AES_DECRYPT(user_name, '[PRINTS FULL AUTH KEY]')] =&gt; a_user_name 
          [2] =&gt; 0000hashedpasswordstring00000 
          [AES_DECRYPT(user_pwd, '[PRINTS FULL AUTH KEY]')] =&gt; 0000hashedpasswordstring00000  
          [3] =&gt; sample@email.com 
          [AES_DECRYPT(user_email, '[PRINTS FULL AUTH KEY]')] =&gt; sample@email.com 
      )
  </code></pre>
  
  <p>This was a secondary solution. Ideally the query would be object-oriented, but that approach was returning an array with the fields but no values.</p>
  
  <p>Clearly, having the full auth key transferred in the results completely defeats the purpose of the encryption. Confused as to why it's returning a combined associate/indexed array, rather than just an indexed array, or just an associative array. Is there a change in SQL syntax that would return <code>[user_email] =&gt; sample@email.com</code> 
  instead of 
  <code>[AES_DECRYPT(user_email, '[PRINTS FULL AUTH KEY]')] =&gt; sample@email.com</code>?</p>