title: How does one insert a MSSQL uniqueindex using PHP's PDO library and prepared queries?
body: <p>Title pretty much says it all. Consider the following table:</p>
  
  <pre><code>CREATE TABLE foobar (
      [guid] UNIQUEIDENTIFIER NULL
  );
  </code></pre>
  
  <p>and the following code snippet:</p>
  
  <pre><code>$stmt = $dbh-&gt;prepare("
      INSERT INTO foobar (
          [guid]
      ) VALUES (
          :guid
      )
  ");
  $stmt-&gt;bindValue(':guid', '0x5E73EFFFFBE83864DD8A23D32A9AB226', PDO::PARAM_INT);
  $stmt-&gt;execute();
  </code></pre>
  
  <p>The reason it is a string and not just a pure integer is because of the way it is generated; like so:</p>
  
  <pre><code>/**
   * Generates a windows-style guid
   * Code here is adapted from http://guid.us/GUID/PHP
   */
  function GUID() {
      if (function_exists('com_create_guid')) {
          return com_create_guid();
      } else{
          mt_srand((double)microtime()*10000); //optional for php 4.2.0 and up.
          $charid = strtoupper(md5(uniqid(rand(), true)));
          $uuid = substr($charid, 0, 8)
                 .substr($charid, 8, 4)
                 .substr($charid,12, 4)
                 .substr($charid,16, 4)
                 .substr($charid,20,12);
          return "0x".$uuid;
      }
  }
  </code></pre>
  
  <p>Profiling the SQL server shows that the query looks like the following:</p>
  
  <pre><code>INSERT INTO foobar (
      [guid]
  ) VALUES (
      '0x5E73EFFFFBE83864DD8A23D32A9AB226'
  )
  </code></pre>
  
  <p>This query will not run correctly.</p>
  
  <p>I'm struggling to figure out how to insert this value. I've tried to convert the value to decimal via base_convert(), but there is a precision loss when I do so. Surely there is a more straight forward way to insert this value no?</p>
  
  <p>Any suggestions?</p>