title: Insert special characters from PHP to Microsoft SQL Server
body: <p>I have just created a MSSQL database.
  The collation is SQL_Latin1_General_CP1_CS_AS.
  I use it from a Linux-Apache-PHP server using freetds.
  When I receive text from a web form, and I try to insert text containing special characters (e.g. café), I get an error.</p>
  
  <pre><code>&lt;?php
  ini_set('display_errors', '1') ;
  $MyConn = mssql_connect( "MSPROD", "one", "1a!logas1" ) ;
  mssql_select_db( "SIAM", $MyConn ) ;
  if ( isset( $_GET['arg'] ) )
      {
      $arg = $_GET['arg'] ;
      print "Inserting '$arg'&lt;br&gt;\n" ;
      for ( $i = 0 ; $i &lt; strlen( $arg ) ; $i ++ )
          {
          print dechex( ord( $arg{$i} ) ) . ' ' ;
          }
      mssql_query( "INSERT mytest VALUES('$arg')" ) ;
      }
  ?&gt;
  &lt;form action=badchars.php method=get&gt;
  &lt;input type=text name=arg&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the error:</p>
  
  <blockquote>
    <p>Inserting 'café' 63 61 66 e9 Warning: mssql_query(): Sybase: Server
    message: Unclosed quotation mark after the character string 'caf'.
    (severity 15, procedure N/A) in /www/one/mytest/badchars.php on
    line 13 Warning: mssql_query(): Sybase: Server message: Incorrect
    syntax near 'caf'. (severity 15, procedure N/A) in
    /www/one/mytest/badchars.php on line 13</p>
  </blockquote>
  
  <p>The fact that it mentions Sybase is because the server was installed for it initially, but it is my understanding that the Sybase and Mssql functions are identical, so it should not matter.
  If I try to put the text strainght into the quotes, I still get the same error:</p>
  
  <pre><code>mssql_query( "INSERT mytest VALUES('café')" ) ;
  </code></pre>
  
  <p>But, if I run the same query in SQL Server Manager it works!
  This works:</p>
  
  <pre><code>mssql_query( "INSERT mytest VALUES('caf' + char(233) )" ) ;
  </code></pre>
  
  <p>What am I doing wrong?</p>