title: SQL Query with binary data (PHP and MySQL)
body: <p>This site had helped me a lot in the past, but now I am lost. Thanks in advance for your guidance.</p>
  
  <p>I have a MySQL table that contains a Binary value, like the example below. I cannot change the table. </p>
  
  <pre><code>CREATE TABLE `test` (
     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
     `nid` binary(16) NOT NULL,
     `test` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`))
  </code></pre>
  
  <p>This an example value of nid: <code>ÞFÈ&gt;ZPÎ×jRZ{æ×</code>  (not all showing, but all 16 are there)</p>
  
  <p>Now I want to create a SQL Query to look for the id of the row where this value is true.</p>
  
  <pre><code>SELECT id FROM test WHERE nid = 'ÞFÈ&gt;ZPÎ×jRZ{æ×';
  </code></pre>
  
  <p>... does not work. Any idea? </p>
  
  <p><strong>SOLUTION</strong>
  Obtaining the nid in HEX format did the trick. It results in DE46C83E5A50CED70E6A525A7BE6D709 and when I use this in the query like this ...</p>
  
  <pre><code>SELECT id FROM test WHERE HEX(nid) = 'DE46C83E5A50CED70E6A525A7BE6D709';
  </code></pre>
  
  <p>I am getting the right result.</p>