0

I'm using PHP 5.3 on FreeBSD. I want to select some utf-8 data (persian characters) from SQL Server database, and write them to a text file, but because of utf-8 does all the characters will be written to file ????. I have searched for two days and read most of the solutions, including:

  1. PHP + SQL Server - How to set charset for connection?

In this question someone says that "There is no Charset parameter in DSNs for the SQL Server PDO driver" and suggests using DBLIB driver, but here I found that that cannot using dblib.

  1. PHP PDO Keep Getting Error: Charset=UTF8 : An invalid keyword charset was specified in the dsn string

What should I do? Using mssql_connect or PDO SQL Server Driver

Also I found that in sqlsrv_connect we can set Charset parameter to UTF-8, but I have got this error:

Fatal error: Call to undefined function sqlsrv_connect()`.

Community
  • 1
  • 1
Bayan B
  • 97
  • 15
  • When you run a query on ssms, do you also get question marks or do you get the actual characters? – Zohar Peled Jun 09 '15 at 07:21
  • I get the right and actual characters on ssms. – Bayan B Jun 09 '15 at 07:24
  • Ok, so the problem is the php, not the sql server. I know nothing about php so I can't help, but I'm sure you are not the first guy that tried using php with utf-8, so someone else is sure to have a solution for you. – Zohar Peled Jun 09 '15 at 07:32

1 Answers1

0

Finally I did it. I have used ODBC Driver for connecting to SQL Server and then do the SELECT.

$pdo = new PDO ("odbc:Driver={SQL Server};Server=$hostname;Database=$dbname; Uid=$username;Pwd=$pw;");

Note: I did this connection in my test environment (Windows 7) and not on FreeBSD.

Bayan B
  • 97
  • 15