title: String data, right truncation in SQLSRV PHP Driver ("donut hole")
body: <p>I'm writing large-ish amounts of text to a <code>text</code> column using Microsoft's sqlsrv PHP driver (on a Windows 2003 server). </p>
  
  <p>There's an odd "donut hole" error, where if the length of the text is fairly small, it is saved successfully, and if the text is sufficiently large, it is also save successfully. In between, we get the following error:</p>
  
  <pre><code>SQLSTATE: 22001
  code: 0
  message: [Microsoft][SQL Server Native Client 10.0]String data, right truncation 
  </code></pre>
  
  <p>The lower limit (to trigger the error) appears to be around 4011 characters, and the upper limit 8024. There are a few other columns in the database that might push it over the power-of-two boundary (4096 and 8192). </p>
  
  <p>This happens regardless of the sql being run. As a test case, we ran the following:</p>
  
  <pre><code>$connectionInfo = array("UID" =&gt; "REDACTED", "PWD" =&gt; "REDACTED", "Database"=&gt;"REDACTED", "CharacterSet" =&gt; "UTF-8");
  
  $conn = sqlsrv_connect("SQLSERVER", $connectionInfo);
  
  $stmt = sqlsrv_prepare($conn, "SELECT LEN(?)", array(&amp;$large_string));
  
  if (!sqlsrv_execute($stmt))
      print_r(sqlsrv_errors());
  
  sqlsrv_free_stmt($stmt);
  
  sqlsrv_close($conn);
  </code></pre>
  
  <p>We've found another table (using <code>varchar(max)</code> columns) that exhibits the same behavior. </p>
  
  <p><strong>Edit:</strong> This occurs when using UTF-8 encoding with a varchar column, but not when using the standard encoding. </p>