php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53171 Problem with accented characterers
Submitted: 2010-10-26 17:44 UTC Modified: 2013-02-18 00:34 UTC
From: kesler dot alwin at gmail dot com Assigned:
Status: No Feedback Package: MySQL related
PHP Version: 5.2SVN-2010-10-26 (snap) OS: Windows XP
Private report: No CVE-ID: None
 [2010-10-26 17:44 UTC] kesler dot alwin at gmail dot com
Description:
------------
When i use mysql_real_escape_string() with mysql_set_charset() forcing to use 'latin1' the accented characters dissapear from the insert string. 

SHOW VARIABLES LIKE 'character_set%';
------------------------------------
character_set_client	  latin1
character_set_connection  latin1
character_set_database	  latin1
character_set_filesystem  binary
character_set_results	  latin1
character_set_server	  latin1
character_set_system	  utf8

PHP info
--------
PHP API 	20041225
PHP Extension 	20060613
Zend Extension 	220060519 

I realize that if i comment the mysql_set_charset() command i have no problems. anyway, if i try to get the connection character (with or without this command) i'll always get 'latin1', but i just think that this commando shouldn't cause problems.. till today i have it trying to stabilize my framework environment

Test script:
---------------
# From the very beginning i disable the magic quotes if it's set
ini_set('magic_quotes_gpc', 0);

# I create a connection like this
$link = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS);
mysql_select_db(SQL_INSTANCE, $link);

# Use the "forced" character set for the connection
mysql_set_charset('latin1', $link);

# In my code i have a class that performs all validation according to the type of content i'm specting... in this case string's validation
Class vaccine
{
  public static function forString($value)
  {
    if($value == null || $value == 'null')
      return 'NULL';
    
    return strlen($value)
         ? '\''. mysql_real_escape_string($value) .'\''
         : 'NULL';
  }
}

# then if i'm going to insert in db
$query = "INSERT INTO TABLE VALUES(". Vaccine::forString('this text has accents from here áéíóú') .")"


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 14:23 UTC] andrey@php.net
-Status: Open +Status: Feedback
 [2010-12-20 14:23 UTC] andrey@php.net
Do you get this also with 5.3?
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 23:01:27 2024 UTC