title: Is This a Bug in MySQL?
body: <p>I am using mysql and php (Laravel) and facing a very strange situation .</p>
  
  <p>I am trying get an encrypted user type and user id and decrypt it . and then find the records for that user id .</p>
  
  <p>my code is like this . i am using Laravel framework .</p>
  
  <pre><code>        $key = Config::get('app.key');
          $decodedUserIDwithType = base64_decode($encryptedUserIDwithType);
          $decryptedUserIDwithType = mcrypt_decrypt(XXXXX , $key, $decodedUserIDwithType, XXXXXX);
          $userIDwithType = $decryptedUserIDwithType;
  </code></pre>
  
  <p>I am expecting the decoded value to be something like this </p>
  
  <pre><code>id@100
  </code></pre>
  
  <p>so i will explode it by @ and find the user id , here it is 100 . </p>
  
  <p>for testing i have changed the encrypted value by manually adding one or two characters . when i decrypt i got something like </p>
  
  <pre><code>id@100������������������������]u甀�+&amp;�fj�W�ZЪS��d��]3�]"
  </code></pre>
  
  <p>and after i explode this i will get the id as <code>100���]u甀�+&amp;�fj�W�ZЪS��d��]3�]"</code></p>
  
  <p>now i select all raws with same id using .</p>
  
  <p>SELECT * FROM table WHERE id=$id</p>
  
  <p><strong>it will select the recordes with id = 100 even the actual id is</strong> <code>100���]u甀�+&amp;�fj�W�ZЪS��d��]3�]"</code></p>
  
  <p>so weird . the type of the id column is <code>INT</code> may be that is why it is matched .</p>
  
  <p>but from my point of view it is very bad , because my whole logic got incorrect because of this .</p>
  
  <p>I checked this query both in Laravel and raw MySQL Query , the results are the same .</p>
  
  <p>Any Ideas , Thanks in advance .</p>
  
  <p><strong>UPDATE</strong></p>
  
  <blockquote>
    <p>I understand the point mentioned by Shadow, but how to handle a
    scenario like this , from decryption i expect id like 100 , but if i
    got something like 1ASASAS, if you cast it to int it will be 1 (this
    is just for example) . now the problem is my database has a user id 1
    also , so now you can see how much trouble i am in because i will get an
    incorrect user , sadly this is related to payment :P . some incorrect
    users wallet will be topped up . ha ha .how to handle this</p>
  </blockquote>