1

I want to use Danish chars on my database (MySqli)

Normally this is not an issue, and i have been running my code with no problem at all. When i recently changed to Unoeuro there was nothing that worked - Same code, same DB, nothing has changed but the hosting service.

Here is how i connect to the database

    <?
$conn=mysqli_connect("MyHost","MyUser","MyPass","MyDB");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

 mysqli_set_charset($conn,"utf8");

?>

The connection to the databse works perfect, but when i send a Danish charto the DB, it changes to another unknown char.

Here is an example of my page that sends data to the mysqli:

    <html>
<head>
  <meta charset="UTF-8">
</head>
<body>
<?
include "config.php"; //The Database connection

/*
Here are a lot of variables, not important in this question
*/

mysqli_query($con,"INSERT INTO WaterWithdrawalLog (XUserID, Location, antalLiter,chipId,note) VALUES('$xuid','$location','$MinusAntalLiter','$usrid','".$_GET["note"]."')");
?>

The Database is set to UTF8_danish_ci

How to i get the Danish chars to show propperly in my database ??

Dharman
  • 30,962
  • 25
  • 85
  • 135
Xelot
  • 33
  • 3
  • 1
    Your question is lacking an important part: How did you find out that "it changes to another unknown char"? Did you check that from within MySQL client? Or did you re-read the entry from within PHP? Or did you dump that entry into a text file or to the console? – Binarus Apr 06 '18 at 06:47
  • I kan see in PHPmyadmin the 'unknown' chars in my data. By unknown i mean very strange chars, not the ones i sent to the database. – Xelot Apr 06 '18 at 07:48

1 Answers1

-1

Use this codes.

$conn->query("SET character_set_results=UTF8_danish_ci");   
$conn->query("SET names=UTF8_danish_ci");
$conn->query("SET character_set_client=UTF8_danish_ci");
$conn->query("SET character_set_connection=UTF8_danish_ci");
$conn->query("SET character_set_results=UTF8_danish_ci");
$conn->query("SET collation_connection=UTF8_danish_ci");

and put meta tags like this on the html page.

<meta charset="UTF8_danish_ci">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

That should do it.

Lahiru Madusanka
  • 270
  • 2
  • 13
  • Many thanks, your code makes sense, but is not solving my problem. - could this have something to do with the fact that i have moved the database from one host to another ?? – Xelot Apr 06 '18 at 07:47