Page 1 of 1

MySQLi errors + SET NAMES support

Posted: Mon May 01, 2006 1:51 pm
by abstract
Serendipity 1.0-beta2

include/db/mysli.inc.php line 236

1.

if (defined('SQL_CHARSET') && $serendipity['dbNames']) {
mysqli_query("SET NAMES " . SQL_CHARSET, $serendipity['dbConn']);
}

bad order of arguments, correct:

mysqli_query($serendipity['dbConn'], "SET NAMES " . SQL_CHARSET );

----

2. for realy support SET NAMES I recommend to add directives:

mysqli_query( $serendipity['dbConn'], "SET CHARACTER SET " . SQL_CHARSET);
mysqli_query( $serendipity['dbConn'], "SET COLLATION_CONNECTION " . SQL_COLLATION_CONNECTION);

----

3.

definition

@define('SQL_CHARSET', 'utf8');

in serependity_lang_xx.inc.php is "too late"

I put it in to serendpity_config_local_inc.php

I added definition

@define('SQL_COLLATION_CONNECTION', 'utf8_general_ci');


this is necesary not only for MySQL5, but also for
PHP5 + MySQL4
/ my charset - czech - unicode /
---

4.

function serendipity_db_matched_rows() {
global $serendipity;

preg_match(
"/^[^0-9]+([0-9]+)[^0-9]+([0-9]+)[^0-9]+([0-9]+)/",
mysqli_info(),

correct:
mysqli_info($serendipity['dbConn']),

----

Josef Moravek

Re: MySQLi errors + SET NAMES support

Posted: Mon May 01, 2006 2:00 pm
by garvinhicking
Hi!

Thanks for reporting these issues.

1. Quite right, I committed the change for this!

2. We do not yet query any collation infos, and only use UTF8 collations, so SET NAMES should actually do the trick? In which cases does that not suffice for you? In which collation are your tables? They should be UTF-8, when created by serendipity in UTF-8 charset. In "native" environments, s9y relies on the default character / collation set of the DB because my collation knowledge is a bit limited :D

3. Why is that definition to late? The language file is included before the mysql connection is initialized.

4. Fixed, thanks a lot!

Best regards,
Garvin

order for included files

Posted: Mon May 01, 2006 2:49 pm
by abstract
Hello,

only to par 3.

ordering included files:

[0]=>
string(43) "/home/wwwprportal/www.prportal.cz/index.php"
[1]=>
string(60) "/home/wwwprportal/www.prportal.cz/serendipity_config.inc.php"
[2]=>
string(56) "/home/wwwprportal/www.prportal.cz/include/compat.inc.php"
[3]=>
string(54) "/home/wwwprportal/www.prportal.cz/include/lang.inc.php"
[4]=>
string(66) "/home/wwwprportal/www.prportal.cz/serendipity_config_local.inc.php"
[5]=>
string(59) "/home/wwwprportal/www.prportal.cz/include/functions.inc.php"
[6]=>
string(55) "/home/wwwprportal/www.prportal.cz/include/db/db.inc.php"
[7]=>
string(59) "/home/wwwprportal/www.prportal.cz/include/db/mysqli.inc.php"
[8]=>
string(66) "/home/wwwprportal/www.prportal.cz/include/functions_config.inc.php"
[9]=>
string(60) "/home/wwwprportal/www.prportal.cz/include/plugin_api.inc.php"
[10]=>
string(65) "/home/wwwprportal/www.prportal.cz/include/plugin_internal.inc.php"
[11]=>
string(66) "/home/wwwprportal/www.prportal.cz/include/functions_images.inc.php"
[12]=>
string(69) "/home/wwwprportal/www.prportal.cz/include/functions_installer.inc.php"
[13]=>
string(67) "/home/wwwprportal/www.prportal.cz/include/functions_entries.inc.php"
[14]=>
string(68) "/home/wwwprportal/www.prportal.cz/include/functions_comments.inc.php"
[15]=>
string(70) "/home/wwwprportal/www.prportal.cz/include/functions_permalinks.inc.php"
[16]=>
string(66) "/home/wwwprportal/www.prportal.cz/include/functions_smarty.inc.php"
[17]=>
string(72) "/home/wwwprportal/www.prportal.cz/lang/UTF-8/serendipity_lang_cz.inc.php"

===

byt at the time of calling functin serendipity_db_connect
there are included only theese files:

[0]=>
string(43) "/home/wwwprportal/www.prportal.cz/index.php"
[1]=>
string(60) "/home/wwwprportal/www.prportal.cz/serendipity_config.inc.php"
[2]=>
string(56) "/home/wwwprportal/www.prportal.cz/include/compat.inc.php"
[3]=>
string(54) "/home/wwwprportal/www.prportal.cz/include/lang.inc.php"
[4]=>
string(66) "/home/wwwprportal/www.prportal.cz/serendipity_config_local.inc.php"
[5]=>
string(59) "/home/wwwprportal/www.prportal.cz/include/functions.inc.php"
[6]=>
string(55) "/home/wwwprportal/www.prportal.cz/include/db/db.inc.php"
[7]=>
string(59) "/home/wwwprportal/www.prportal.cz/include/db/mysqli.inc.php"
[8]=>
string(66) "/home/wwwprportal/www.prportal.cz/include/functions_config.inc.php"
[9]=>
string(60) "/home/wwwprportal/www.prportal.cz/include/plugin_api.inc.php"
[10]=>
string(65) "/home/wwwprportal/www.prportal.cz/include/plugin_internal.inc.php"
[11]=>
string(66) "/home/wwwprportal/www.prportal.cz/include/functions_images.inc.php"
[12]=>
string(69) "/home/wwwprportal/www.prportal.cz/include/functions_installer.inc.php"
[13]=>
string(67) "/home/wwwprportal/www.prportal.cz/include/functions_entries.inc.php"
[14]=>
string(68) "/home/wwwprportal/www.prportal.cz/include/functions_comments.inc.php"
[15]=>
string(70) "/home/wwwprportal/www.prportal.cz/include/functions_permalinks.inc.php"
[16]=>
string(66) "/home/wwwprportal/www.prportal.cz/include/functions_smarty.inc.php"

not the:

"/home/wwwprportal/www.prportal.cz/lang/UTF-8/serendipity_lang_cz.inc.php"

I'll prepeare better info for SET NAMES.

Josef Moravek

Re: order for included files

Posted: Mon May 01, 2006 3:56 pm
by garvinhicking
Hi!

First of all, I am very thankful that you are helping on this issue. You must know that I'm just a simple ISO-/UTF-8 guy who rarely uses special character sets, so my knowledge with MySQL. So it is great to have someone who seems to have a much better knowledge than me to help in this area!

Serendipity 1.0 is currently in a feature-frozen state, and also doesn't really support the "dbNames" config option at all. Support for this was only officially added to Serendipity 1.1 Trunk releases.

Thanks to your help I only now recognized that you are right the command is called useless. So I patched up the way of the function call so that the SET NAMES is issued after the language file is loaded. This will then maybe not properly fetch the serendipity_config DB data if it is stored in specific format, but we need that _config* information to initialize the language file. Maybe the whole workflow of that needs to be rethought.

The commit I made to 1.1 is this one:
http://svn.berlios.de/viewcvs/serendipi ... 8&view=rev

I'd love if you can help us further with this issue(s)!

Best Regards,
Garvin

post connection queries

Posted: Mon May 01, 2006 10:43 pm
by abstract
Garvin,

I am not a charsets guru,
but I know, that in some combinations of versions
PHP x MySQL it's necesary to send some post connection SQL queries for correct charset functions.

Your solution is a little dangerous:
If some user changes his language version, it's not ideal to change
SET NAMES + SET CHARACTER SET queries, it could be danger for data, when somebody edit entry in different character set.

Charset setting - / ideal unicode / - is one thing and language version for gui could be changed per user.

So I prefer to define post connection queries in serendipity_config_local and let users to change their lang version.

In this case users cannot change collation - alphabet order - but it's not a big issue.

Important is, that for correct connection from PHP5 to MySQL4 via both mysqli and mysql extension, is necessary to set
SET NAMES
and
SET CHARACTER SET
and for collation also
SET COLLATION_CONNECTION

that's why I started hacking Your code.

Good luck with Serendipity.

Josef Moravek

Re: post connection queries

Posted: Tue May 02, 2006 9:22 am
by garvinhicking
Hi!

Hm, can you explain me why collation informations are needed? All the s9y collations are created in UTF8 unicode, so IMHO apart from the SET NAMES there should be no need to set other directives? I'm not good at those things, so I'm trying to improve my knowledge. :)

About changing language: Having different languages co-exist on a blog require that you set your language charset to UTF-8. In that case, languages should be changable without corrupting data, because UTF-8 characters always stay the same...

Best regards,
Garvin