0

I have a joomla database, where the mySQL connection collation is utf8_general_ci. I have some additional datatables in the database (not related to the joomla installation) that I want to populate with data from a PHP script.

LATER EDIT: check below

When I try inserting special characters (language and region specific characters) I get jibberish in the database, like îăîșț instead of îăîșț.

The collation for all the columns in the joomla database is : utf8mb4_unicode_ci (if this makes any difference)

The weird thing is, that if I show the content of the database in an email / mobile app (browser based) it shows the data correctly. But I can see, that something is not right with inserting the valus from PHP, since if I insert it manually from the phpmyadmin panel, the value will be correctly displayed in the table.

<?php header('Content-type: text/html; charset=UTF-8');  //header is specified here

$value_to_insert = addslashes($_REQUEST['value']);   //get the value from the parameter

inserttask($value_to_insert); //insert the value into the datatable

function inserttask($value_to_insert)
{
    $con = mysqli_connect("host",username,password,database); //set up my mysqli connection
    //mysql_set_charset('utf8'); //this didn't help

    if (!$con)
    {
        die();
    }

    $sql = "INSERT INTO `table` (`value`) VALUES ('".mysqli_real_escape_string($con, $value_to_insert)."')";

    if($result=mysqli_query($con,$sql))
    {
        print "OK";
    }
    else
    {
        print "ERROR";
    }
}

?>

Any ideas how this insert should be made, to make it compatible with any region dependend character?

Later edit: I ran the "show variables like '%collation%'" collation_connection - utf8_general_ci collation_database - latin1_swedish_ci collation_server - latin1_swedish_ci

Could this be the problem?

2
  • Have you tried mysql_set_charset('utf8mb4'); ? Commented May 12, 2016 at 14:02
  • Yes. And if I do the following: mysqli_set_charset('utf8'); print $con->character_set_name(); it will print out "Latin1" instead of utf8 Commented May 12, 2016 at 14:14

1 Answer 1

1

After setting up the connection as I had to change the connections charset in a specific way.

$con = mysqli_connect("mydb12.surf-town.net","bosteen_licadm","Ugymate92","bosteen_p2p");

$con->set_charset("utf8");

After this, the insert works!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.