Question marks returned instead of Arabic characters ONLY when xampp servers are launched from within program

42
February 12, 2019, at 09:40 AM

As the title says, question marks are returned only when I run mysqld.exe and httpd.exe from within my java program. However, when I run xampp.exe and start apache and mysql from the UI it works perfectly. I am using slim 3 framework with mysql database.

I've tried setting character set in every possible way: setting the slim application configurations, setting the database character set, writing response using JSON_UNESCAPED_UNICODE, etc.

// Slim application configuration
$config = [ 'charset' => 'utf-8' .....]
// .htacess file
AddDefaultCharset utf-8
// my.ini was already configured
// $response in php function
return $response->withHeader('Content-Type', 'application/json')->withStatus(200)->withJson($json_response, null, JSON_UNESCAPED_UNICODE);

However, since the problem is being resolved when I manually run xampp I'm thinking maybe there is some file that should run alongside the ones mentioned above. If not, is there a way to work around this?

EDIT: I tried inserting data through the api instead of manually inserting it using a query in phpmyadmin. This inserted data was the only line that returned correctly. Note that I inserted the data while the server was run from within my java program.

Answer 1

I fixed the problem by setting PDO correctly. (Check OP comments)

$pdo = new PDO ("mysql:host=localhost;dbname=database;charset=utf8", "user", "pass");

The reason the data inserted through the api was being retrieved correctly is that it was sent in a the same charset that PDO was set to. When I tried to retrieve it after setting the PDO it was malformed.

READ ALSO
MySQL - sub query on the same table [duplicate]

MySQL - sub query on the same table [duplicate]

This question already has an answer here:

25
How to update image in mysql database using angularjs [on hold]

How to update image in mysql database using angularjs [on hold]

I am learning angularjsBut I am fetching some problem in image updating

45
mysqli_error() expects parameter 1 to be mysqli, null given ERROR

mysqli_error() expects parameter 1 to be mysqli, null given ERROR

I'm setting up a new server and having some issues with outdated coding

50
mysql composite primary key with dates [on hold]

mysql composite primary key with dates [on hold]

I have a table with 3 columns

11