lubomir.brindza
lubomir.brindza

Reputation: 286

php and mssql/sqlsrv - column names containing question marks instead of accented characters

I'm trying to dump some reports to HTML from a MSSQL 2005 database, but there is a slight problem when trying to display column names (not the column data itself, that's displaying properly) that have accented characters in them - they are replaced by question marks instead.

I'm using the sqlsrv driver for PHP, running under IIS7. PHP script itself is UTF-8 encoded. I'm connecting to the SQL server as:

  $connection_info = array("Database" => "ProjectManager", "UID" => DB_USER, "PWD" => DB_PASS , "CharacterSet" => "UTF-8");
  $conn = sqlsrv_connect(DB_HOST, $connection_info) or die("FAIL");

The first thing after running the query is dumping column names into a table:

$qry = "EXEC [dbo].[dummy_report] @year=2012, @month=3";
$res = sqlsrv_query($conn, $qry);
foreach(sqlsrv_field_metadata($res) as $fieldData) {
    echo "<th>".$fieldData['Name']."</th>";
}

This handles data stored in the database well enough; column names - not so much:

enter image description here

Normally, I wouldn't go about naming database columns in Slovak, but I'm just trying to display the result of a stored procedure and I'm not really comfortable hardcoding those field names into the PHP script.

So, charsets. Wat do?

Upvotes: 2

Views: 3056

Answers (1)

user3243582
user3243582

Reputation: 11

I have encountered the same problem as you did. And after a lot of googling, it turns to be a BUG of "Microsoft Drivers for PHP for SQL Server".

See more info here:PHP sqlsrv 3.0.1 Driver: sqlsrv_field_metadata returns column name as char*, so unicode column names can't be fetched correctly.

Upvotes: 1

Related Questions