News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

small SSI modification (encoding and database)

Started by BogdanNB, May 24, 2011, 02:39:25 PM

Previous topic - Next topic

BogdanNB

Hi All!

I propose to do a centralized modification/revision of the SSI.php file... it is a very small change (addon) concerning DB connection.

In few words about my problem:
I use SSI.php for users authorization on my site and other functions and features of SSI... but mostly I use a database connection that is created in SSI.php and inner SMF method - db_query() - for direct work with DB data...
I use UTF-8 version of SMF (with russian language pack) and all my scripts are in the UTF-8... everything was fine while I worked with the english content of the forum, .. but when I sent a database query containing russian characters (russian board name - smf_boards.name field):

...
$request = db_query("
      SELECT hxxp:b.id [nonactive]_BOARD
      FROM {$db_prefix}boards AS b
      WHERE hxxp:b.id [nonactive]_CAT = $category_ID AND hxxp:b.name [nonactive] = '$board_name'", __FILE__, __LINE__);
...


I've faced problem with string/query encoding (collation problems) - attempt to compare UTF-8 field value with cp1251 string value... at that time while all my files/scripts saved in UTF-8.
To solve this problem, I used the standard directive, which I use since switching to UTF-8 - I've added only one query in the SSI.php (in bold below):

...
// Connect to the MySQL database.
if (empty($db_persist))
   $db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
else
   $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
if ($db_connection === false)
   return false;

mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'", $db_connection);

// Add the database onto the prefix to avoid conflicts with other scripts.
if (strpos($db_prefix, '.') === false)
   $db_prefix = is_numeric(substr($db_prefix, 0, 1)) ? $db_name . '.' . $db_prefix : '`' . $db_name . '`.' . $db_prefix;
else
   @mysql_select_db($db_name, $db_connection);
...


So... maybe it makes sense to do a centralized review of the SSI.php - include similar modification for the SSI functional for different cases (encodings)?

Thanks a lot for your great work!
Bogdan.

Advertisement: