1

Hello I have this problem: I have MySQL Database with collation latin1_bin. In database I have table with collation utf8_slovak_ci. All collumns is text. In rows I have values with ť í ž ľ š č(utf8) chars, but PHP code returns values with utf8 chars replaced by � , ? and other not readable chars. In html head I have set charset to utf-8. Please help me. I have this code:

//From config file
define ("DATABASE_SERVER", "localhost");
define ("DATABASE_LOGIN", "root");
define ("DATABASE_PASSWORD", "root");
define ("DATABASE_DATABASE", "novymost");

mysql_connect(DATABASE_SERVER, DATABASE_LOGIN, DATABASE_PASSWORD)or die(mysql_error());
mysql_select_db("novymost")or die(mysql_error());
$results=mysql_query("SELECT * FROM Downloads") or die(mysql_error());
$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

while($rows = mysql_fetch_array($results))
{
echo("<li>");
echo "<a href=\"".$rows["URL"];
echo("\">");
echo "".$rows["TITLE"];
echo(" - ".$rows["SIZE"]);
echo("</a>");
echo("<br/></li>");
}
1
  • What does your DOCTYPE look like? Commented Apr 28, 2011 at 18:17

2 Answers 2

3

run the query

mysql_query( "set names utf8" );

before runnign any other queries. This sets the connection charset

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

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

Comments

2

In php:

header("Content-Type: text/html; charset=UTF-8");

In HTML:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

In Database before queries:

mysql_query( "set names utf8" );

Or you can also convert you latin-table to a UTF8-table:

INSERT INTO utf8table (utf8column) 
SELECT CONVERT(latin1field USING utf8)
FROM latin1table; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.