0

For some reason I cant retrieve data from a query to a username with accent marks, but the same data retrieving works perfectly if the user has no accent marks.

This is the PHP query:

$query = "SELECT * FROM [dbo].[Users] WHERE User= 'Róger'";
$result = sqlsrv_query($conn, $query);
$row = sqlsrv_fetch_array($result);
$UserID = $row['ID'];
echo "ID is: " . $UserID;

This is my result on website:

ID is:

This is what i get from var_dump($query);

"SELECT * FROM [dbo].[Users] WHERE User= 'Róger'"

Now, if we change $query from

$query = "SELECT * FROM [dbo].[Users] WHERE User= 'Róger'";

to

$query = "SELECT * FROM [dbo].[Users] WHERE User= 'Robert'";

Then it properly shows up the UserID.

Any ideas?

  • SQL Server or MySQL? – Dharman Apr 22 '19 at 10:34
  • This sounds like an encoding problem in your PHP script (assuming the same queries would work executed directly on MySQL). – Tim Biegeleisen Apr 22 '19 at 10:37
  • Its SQL Server, sorry for the wrong tag. In fact querys are directly working on MySQL. All I have related on my enconding PHP script is: ini_set('mssql.charset', 'utf-8'); and the DB connection. The rest of the file is just this query and this echo, since i'm trying to solve it from a different file. – Patrick Ben Apr 22 '19 at 10:38

2 Answers2

1

It got fixed by adding 'CharacterSet' => 'UTF-8' to the DB connection file.

0

I suggest you do not use * for this call. If necessary, list all required columns instead of *.

I guess, It seems that this is enough to put the userid in here.

SELECT UserID FROM [dbo].[Users] WHERE User= N'Robert'

you need use N or use UTF-8

Amirhossein
  • 1,148
  • 3
  • 15
  • 34