title: Binary data not stored properly in MySQL
body: <p>I want to store a base64_encoded string as binary data. So use base64_decode() on the string before inserting in a LONGBLOB field of MySQL. So far so good, however when I retrieve the data from MySQL, I can't generate the correct base64_encoded string which I have started with...</p>
  
  <p>How is this possible? Thanks in advance</p>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p>The stored data is an encrypted string with AES-256CBC OPENSSL encryption routine.</p>
  
  <p><strong><em>CODE</em></strong></p>
  
  <p>For my code I use OpenSSL to encrypt a string</p>
  
  <pre><code>$string = "Test";
  $IV = "1234567890123456";
  $key = "12345678901234561234567890123456";
  $encrypted = openssl_encrypt($string, "AES-256-CBC", $key, false, $IV);
  
  $encrypted string is stored in LONGBLOB field by 
  $sql_insert_data = $mysqli-&gt;prepare("INSERT INTO `TBLName` (String) Values(?)");
  $sql_insert_data-&gt;bind_param('s', $mysqli-&gt;real_escape_string($encrypted));
  
  //Thereafter, it is retrieved by a select statement
  $decrypted = openssl_decrypt($row['String'], "AES-256-CBC", $key, true, $IV);
  </code></pre>
  
  <p>When I do base64_encode on the string and store that as a TEXT value in the DB, the above works. However, when I do not, the above does not work...</p>
  
  <p>Thanks</p>