I have MySQL 5.0 server, and a database which uses cp1251_general_ci collation.

All the data are in cp1251.

PunBB is using Russian as default language, encoding in lang/Russian/common.php is set to windows-1251.

Everything is ok with the language pack, but the messages that are written in russian language, all appear as "???????? ??? ?????"

I have already known such issue, and I decided to add the following line to
lang/Russian/common.php ( after having changed $lang_common['lang_encoding'] to "CP1251"):

$db->query('SET NAMES '.$lang_common['lang_encoding']);

However, I think I just haven't found an easier way to solve this problem.

My solution is simple and is based on Apache module mod_rewrite.

1. Put a .htaccess file in your PunBB installation directory.

.htaccess:

RewriteEngine On

RewriteBase /your/path/here/

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule (.*) punbb_wrapper.php [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule ^/?$ punbb_wrapper.php [L]

2. Put a punbb_wrapper.php to the same directory.

punbb_wrapper.php:

<?php

$uri = parse_url($_SERVER['REQUEST_URI']);
if (@$uri['path'] == ($self_dir = dirname($_SERVER['PHP_SELF'])) ||
    @$uri['path'] == $self_dir."/") {
    $inc = dirname(__FILE__)."/index.php";
} elseif (is_file($inc = dirname(__FILE__)."/".basename($uri['path']))) {
    ;
} else {
    die("Illegal usage");
}

// getting HTML generated by PunBB
ob_start();
include_once($inc);
$_ob_contents_punbb = ob_get_contents();
ob_end_clean();
// got HTML generated by PunBB

/**
* Voila!
*
* in the $_ob_contents_punbb variable is the whole HTML output of PunBB page
*
* We could now simply write
*
* echo $_ob_contents_punbb;
* (this is, as you can see, not in any way sensible :-)) )
*
* Or use $_ob_contents_punbb in some other way (for example:
*  $my_smarty->assign('punbb_html', $_ob_contents_punbb);
* )
*
*/

?>

Forgot to mention:
there _is_ one line of PunBB php code that has to be changed if you want to succeed with my approach.
line 161 of footer.php must be changed from

exit($tpl_main);

to

echo($tpl_main);

Have fun ))

-------------- Rubbish before this line ------------------
Sorry everybody. I'm new to PunBB and haven't discovered the <pun_include> template directive before current minute...