Edit report at http://bugs.php.net/bug.php?id=52267&edit=1

 ID:                 52267
 Updated by:         u...@php.net
 Reported by:        gutzmer at usa dot net
 Summary:            add collation to mysqli::set_charset
 Status:             Verified
 Type:               Feature/Change Request
 Package:            MySQLi related
 PHP Version:        Irrelevant
 Assigned To:        mysql
 Block user comment: N

 New Comment:

Such a function is not needed and does not exist in MySQL C API. 



You shall not use SET NAMES to change a *charset* because an existing
connection handle will not be aware of the change. The connection handle
will continue to use the charset set during the creation of the
connection. The connection handle will potentially use the wrong charset
for mysqli_real_escape_string(). 



This is why you shall use mysqli_set_character_set to set the *charset*
because this is something the connection handle can detect for use with
mysqli_real_escape_string().



The *collation* is about sort order. Collation is irrelevant for
escaping strings on the client. And this is why the C API
mysql_set_character_set does not have the additional parameter you
want:

http://dev.mysql.com/doc/refman/5.1/en/mysql-set-character-set.html



So, use mysqli_set_charset() to set the charset and then SET NAMES to
change the collation.


Previous Comments:
------------------------------------------------------------------------
[2010-07-06 19:07:01] gutzmer at usa dot net

Description:
------------
According to the docs,  mysqli::set_charset "is the preferred way to
change the charset. Using mysqli::query() to execute SET NAMES ..  is
not recommended."



But when using the MySQLi extension, the only way to use a collation
other than the default for a particular charset is to send a SET NAMES
... with a COLLATION clause.



mysqli::set_charset should have a second (Optional) "string $collation"
parameter to allow users to set the charset and collation without
resorting to the 'not recommended' direct query method.  When the
optional parameter is not set, is null, casts to Boolean FALSE, or is an
invalid choice for the charset passed in the first parameter, the
connection should use the default collation for the selected charset.



MySQL already handles error conditions relating to charset/collation
mismatches, so there should be no great added overhead to the source
code logic implementing  the MySQLi function.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52267&edit=1

Reply via email to