Recent Topics

1 May 26, 2009 21:09    

I'm in the first stages of developing a plug in to display the most popular entries of my blog, which is in mixed Russian and English, running b2evolution 2.4.2-stable-2008-04-27 under MySQL 5.0. The blog works perfectly, and most of the fields are in MySQL collation set utf8_general_ci.

The code I'm using is:


mysql_connect('myservername', 'myusername', 'mypassword') ;
mysql_select_db('mydatabase') ;

$query = 'SELECT * FROM evo_items__item ORDER BY post_views DESC LIMIT 0, 10' ;
$contents = mysql_query($query) ;
while ( $row = mysql_fetch_array($contents) )
	  {
	  print "{$row['post_views']} ";
	  print "{$row['post_urltitle']} ";
	  print "{$row['post_title']} \n";
	  }

This works perfectly except for one thing: the post_title values print out as a string of question marks. That is, the output looks like this:


725 guestbook Guest book & general comments. 
663 -27 ?????? ???? 
582 -114 ???????-??????? 
511 -116 ????? 
485 -115 ??????/???????? 
423 -189 ?????????, ???? 
407 -19 ????? 
404 -112 ?????????? ????? (????????? ?????) 
385 -161 ????? 
360 -119 ???????????? ?????

The html in which it is embedded has a properly marked UTF-8 header, specifically:

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

which works flawlessly in my normal Russian pages. What do I need to do differently to get the UTF-8 to work correctly? I suspect a problem in the hand off of the data from MySQL to PHP, but I don't see any place in either of them to specify that a data value is UTF-8. Any hints?

2 May 26, 2009 21:28

Oof. I have found my own answer. After connecting to the database, I added:

$query = 'SET NAMES utf8' ;
mysql_query($query) ;

That solved the issue.

4 May 27, 2009 15:55

@deljt look at the database API on b2evolution, you don't need to connect to mySQL, you can use the connection of b2evolution. And of course, you can use the ministats plugin.

5 May 27, 2009 17:03

You only need to build your own $ItemList with the right filters ;)

¥


Form is loading...