Charset Mysql and PHP

Asked

Viewed 94 times

3

My mysql table is UTF-8 formatted and all accents appear correctly, but when I request with PHP and display the data they do not appear in UTF-8 format.

p.s: my page already has the goal for utf-8.

you know what might be causing this problem?

  • I had problems that may be yours, here is the link:
 http://stackoverflow.com/questions/26824163/json-return-nullor-char-code

  • I believe this answer should solve the problem: http://answall.com/a/43205/3635

  • You created the records in the table manually?

1 answer

3

How is your connection made, Mysql Conect, Mysqli, PDO?

I think that would be the solution:

@mysql_query("SET NAME 'utf8'");
@mysql_query("SET character_set_connection=utf8");
@mysql_query("SET character_set_client=utf8");
@mysql_query("SET character_set_results=utf8");

PDO:

$db = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf-8", $dbUser, $dbPass);
$db-> exec("SET CHARACTER SET utf8");

Mysqli:

$con=mysqli_connect("localhost","user","pass","db");
// Verifica conexão
if (mysqli_connect_errno())
  {
  echo "Falha ao fazer conexão: " . mysqli_connect_error();
  }

// Set utf8
mysqli_set_charset($con,"utf8");

mysqli_close($con);
?>

CODIGNITER:

Please check if config.php and database.php are like this

config.php

`$config['charset'] = 'UTF-8'

database php.:

$db['default']['char_set'] = 'utf8'; 

and

$db['default']['dbcollat'] = 'utf8_general_ci';

UFT-8 IN AJAX REQUISITION:

.ajax({
        async: false,
        type: "GET", 
        url: url, 
        contentType: "charset=utf-8", 
        success: function(data)
            { 
                $(".container").html(data);
            }
});

HEADER:

header('Content-type: text/html; charset=utf-8');

Make sure that all your files are saved as UTF-8 (UTF-8 or w.o BOM). Set up formatting in your IDE.

  • is connected via PDO and I am using Codeigniter! you know how to fix this in the framework?

  • @Rafaelacioly -> I edited the answer.

  • Everything is already the way you commented; when I do the query in the database to display in the admin panel the format utf-8 appears normally, but when I do a request in index (for example) the formatting does not work even the meta charset is already set.

  • Put the code, it’s easier to help you. I’ll edit the answer again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.