title: How to set charset in mssql_connect?
body: <p>I'm using <code>PHP 5.3</code> on <code>FreeBSD</code>.
  I want to select some <code>utf-8</code> data (persian characters) from <code>SQL Server</code> database, and <strong>write them to a text file</strong>, but because of <code>utf-8</code> does all the characters will be written to file  ????.
  I have searched for two days and read most of the solutions, including:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/1322421/php-sql-server-how-to-set-charset-for-connection">PHP + SQL Server - How to set charset for connection?</a></li>
  </ol>
  
  <p>In this question someone says that "There is no Charset parameter in DSNs for the SQL Server PDO driver" and suggests using <code>DBLIB</code> driver, but <a href="http://php.net/manual/en/ref.pdo-dblib.php" rel="nofollow noreferrer">here</a> I found that that cannot using dblib.</p>
  
  <ol start="2">
  <li><a href="https://stackoverflow.com/questions/18948478/php-pdo-keep-getting-error-charset-utf8-an-invalid-keyword-charset-was-specif">PHP PDO Keep Getting Error: Charset=UTF8 : An invalid keyword charset was specified in the dsn string</a></li>
  </ol>
  
  <p>What should I do? Using <code>mssql_connect</code> or <code>PDO SQL Server Driver</code></p>
  
  <p>Also I found  that in <a href="http://php.net/manual/en/function.sqlsrv-connect.php" rel="nofollow noreferrer">sqlsrv_connect</a> we can set <code>Charset</code> parameter to <code>UTF-8</code>, but I have got this error: </p>
  
  <blockquote>
    <p>Fatal error: Call to undefined function sqlsrv_connect()`.</p>
  </blockquote>