title: PDO suspected of escaping characters of my Blob in MySql
body: <h2>Context</h2>
  
  <p>I store image in BLOBs columns in a MySql DB with PDO (<em>yeah, this is needed</em>).</p>
  
  <p>I upload a <code>base64_encoded</code> .png from client's browser to a .php webservice through AJAX, and store it on my data base using <code>base64_decode()</code>.</p>
  
  <p>Later, I get it back on the client's browser. And upload it again, and so on until space-time continuum breaks.</p>
  
  <p><strong>Retrieving</strong> a valid BLOB (imported directly on phpMyAdmin, so 100% sure) from the database is fine, I can print it well on browser.</p>
  
  <p>But <strong>storing it</strong> on MySql...</p>
  
  <hr>
  
  <h2>Issue</h2>
  
  <p>Setting looks like that :</p>
  
  <pre><code>$dbh = new PDO('mysql:host=localhost;dbname=Me', 'My', 'Myself');   
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $dbh-&gt;exec("SET CHARACTER SET utf8"); //I tried playing with charset too
  
  $query = $dbh-&gt;prepare("UPDATE i_like_underscores SET `my_blob`=:my_blob WHERE `it`=`:belongs");
  
  $my_blob = base64_decode($_POST['my_blob']);
  $query-&gt;bindParam(':my_blob', $my_blob, PDO::PARAM_LOB);
  //The WHERE clause has really no importance here, so I don't even bind it
  $query-&gt;execute();
  </code></pre>
  
  <p>It seems that <strong>PDO systematically removes some special characters</strong> of my blob during this process (but I can't diagnostic when exactly), cause when I later get my picture back (and encode it on base64), <strong>all the <kbd>+</kbd> and <kbd>=</kbd> are gone from my base64 string</strong> (while <kbd>/</kbd> stills) === corrupted.</p>
  
  <p>I guess it automatically escapes when I bind it, but I can't tell as <code>base64_decoded</code> .png data is encoded in a unreadable weird charset.</p>
  
  <p>I spent many hours on it, and tried :</p>
  
  <ul>
  <li>Changing the encoding</li>
  <li><code>PDO::quote()</code> after base64_decode()</li>
  <li>Putting various quotes on my SQL query</li>
  <li>Prepared statements and direct <code>PDO::query</code></li>
  <li>Surfing the web for docs on all the PDO function I used</li>
  <li>Finding similar cases, on StackOverflow too, no luck</li>
  <li>To see how it's done in phpMyAdmin</li>
  <li>Setting type <code>PDO::PARAM_STR</code></li>
  <li>Not thinking about quitting PDO just for that special case</li>
  <li>Writing all my code backwards</li>
  <li>And black magic</li>
  </ul>
  
  <p>Without luck... Could someone give me a clue?</p>