This question already has an answer here:
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?
</div>
It got fixed by adding 'CharacterSet' => 'UTF-8'
to the DB connection file.
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