MySQL. Insert UTF-8 characters to database -


i need add usernames facebook database , these names have utf-8 characters (ą,č,ę,ė,į,š,ų,ū). when add database example letter š looks Å¡

in myphpadmin found table setting set encoding utf-8, did same problem. added mysql_set_charset('utf8'); code, wont helped too. code looks like:

<?php      $time = $_post['time'];     $username = $_post['username'];      session_start();     $name = $_session['vardas'];      $times = gmdate('h:m:s', $time);      mysql_set_charset('utf8');     $mysqli = new mysqli("localhost","my_db","pass","my_db"); if ($stmt = $mysqli->prepare("insert eurokos (time, username) value (?,?) ")) {  $stmt->bind_param('is', $time, $name);   // $stmt->bind_param("s", $username);     $stmt->execute();     if ($stmt->error != '') {        echo ' error:'.$stmt->error;    } else {        echo 'success';    }    $stmt->close(); } else {    echo 'error:'.$mysqli->error; } 

also php file converted utf-8 encoding, wont helped.

when use code echo "name: " . $user_profile['name']; facebook correctly printing username normal letters in utf-8. problem inserting usernames database.

this use send username variable fb.php db.php (maybe here need use encoding?)

$name = $user_profile['name']; session_start(); $_session['vardas'] = $name; 

could me? thanks.

this solved problem:

if (!$mysqli->set_charset("utf8")) {     printf("error loading character set utf8: %s\n", $mysqli->error); } else {     printf("current character set: %s\n", $mysqli->character_set_name()); } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -