Install utf8 using mysql via php

I have the following very simple code that retrieves utf8 formatetd data, such as containing umlauts from the mysql database, which may or may not be installed as utf8. If I use any of the commented approaches to ensure utf8 data is returned, the data will NOT be returned as utf8, however, if I do not delete it, the data will be displayed. Why does utf8 force negate data mapping as utf8?

<?php $con = mysqli_connect("localhost", "x", "", "x"); //$con->query("SET NAMES 'utf8'"); //$con-set_charset('utf8'); $recordsQuery = "SELECT ARTICLE_NAME FROM AUCTIONS1"; if ($getRecords = $con->prepare($recordsQuery)) { $getRecords->execute(); $getRecords->bind_result($ARTICLE_NAME); while ($getRecords->fetch()) { echo "<p>$ARTICLE_NAME"; } } else { print_r($con->error); } 
+1
php mysql character-encoding
Mar 08 '09 at 21:15
source share
2 answers

Perhaps the error lies in the encoding with which you serve the page. If you get UTF-8 content from a database and serve it using the default HTML encoding for Windows-1252, then it will look garbled. Make sure you have the equivalent of this:

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

in your PHP code.

+3
Mar 08 '09 at 21:40
source share
  • Make sure your data is already encoded in your UTF-8 database.
  • configure the database for UTF-8 delivery (e.g. SET NAMES 'utf8')
  • use the correct encoding on your website (nod to the stack).

If you still have problems, provide more data, especially what is expected and what is finally delivered

0
Mar 08 '09 at 22:13
source share



All Articles