up vote 1 down vote favorite
share [fb]

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>");
}
link|improve this question
What does your DOCTYPE look like? – fredley Apr 28 at 18:17
<!DOCTYPE html> – Mato Kormuth Apr 28 at 18:18
feedback

2 Answers

up vote 3 down vote accepted

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

link|improve this answer
Working. Thanks! – Mato Kormuth Apr 28 at 18:31
feedback

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; 
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.