1

I can get UTF-8 letters from database for example these: ąčęėįšųūž, but can't insert them to database, for some reason only š gets inserted into database, the rest are inserted as ?. I'm connecting to my database through this file:

<?php
    $GLOBALS['mysqli'] = new mysqli("...", "...", "...", "...");

    $stmt = $GLOBALS['mysqli'] -> prepare("SET NAMES 'utf8'");
    $stmt->execute();
?>

And then inserting data through this code:

$linkName = $_POST['linkName'];

$stmt = $GLOBALS['mysqli'] -> prepare
("
    INSERT INTO NavigationLinks (linkName, fileName, iconExt)
    VALUES (?, ?, ?)
");

$stmt->bind_param("sss", $linkName, $fileName, $iconExt);
$stmt->execute();
$stmt->close();

Before insertion I've tried to echo $linkName and it outputs correct characters.

Donatas
  • 41
  • 5

1 Answers1

3

Use a UTF8 encoding/collation on the tables and columns you want to add UTF8 data to.

John Corry
  • 1,567
  • 12
  • 15