My server database has a table with collation: greek_ci_ai and The problem is that greek characters are showing up as question marks(????)
i tried
header("Content-Type: text/html; charset=iso-8859-7")
and
<meta charset="utf-8" />
but the problem still remains and I can't figure out how to solve it
Asked
Active
Viewed 225 times
0

Legend Whirlwind
- 31
- 7
-
What happens if you use `utf8_encode($string)` on the result string? – Matthias Bö May 31 '18 at 17:31
-
Also, are you sure that the values are being stored as an `nvarchar` not a `varchar`. What is the query that is returning the values? – Thom A May 31 '18 at 17:37
-
2First of all, what charset is the string *actually* stored as, and what do you expect it to look like? Second, post a `bin2hex($problem_string_here);` so we can inspect the data. Third, you should probably read this: https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch May 31 '18 at 18:14
-
i have an input type='text' in html to insert some values in database with php post and the query is a simple Select * from table1 with sqlsrv $sql = "SELECT * FROM JobLocations"; $stmt = sqlsrv_query($connection,$sql); thank you in advance because im not familiar with encoding – Legend Whirlwind Jun 01 '18 at 09:42
-
also the values in database are nvarchar and i tried the echo mb_detect_encoding($sql); and the result was ASCII – Legend Whirlwind Jun 01 '18 at 11:01
-
the problem it was in connection string because i missed to put "CharacterSet" =>'UTF-8' everything is fine – Legend Whirlwind Jun 01 '18 at 12:32
1 Answers
2
You can try editing your connectionInfo to include "CharacterSet"=>"UTF-8" as below:
$serverName = "localhost";
$connectionInfo = array("Database"=>"DBName",
"UID"=>"UserName",
"PWD"=>"Password",
"CharacterSet"=>"UTF-8");
$con = sqlsrv_connect($serverName, $connectionInfo);
if ($con === false) {
echo "Connection could not be established.<br />";
die(print_r(sqlsrv_errors(), true));
}

Jacek B Budzynski
- 1,393
- 1
- 7
- 13

vts1979
- 36
- 3