Req #69348 [NEW]: mysql_real_escape_string produces invalid decimal numbers on some locales
| From: | mdrolc at gmail dot com | Date: | Wed, 01 Apr 2015 14:19:54 +0000 |
| Subject: | Req #69348 [NEW]: mysql_real_escape_string produces invalid decimal numbers on some locales | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191768@lists.php.net to get a copy of this message | ||
From: mdrolc at gmail dot com
Operating system: All
PHP version: 5.6.7
Package: MySQL related
Bug Type: Feature/Change Request
Bug description:mysql_real_escape_string produces invalid decimal numbers on some locales
Description:
------------
SQL only accepts floats with dot as the decimal separator. But running a
float through mysql_real_escape_string() returns a string with comma as
the decimal separator on some locale configurations. MySQL fails
silently and just cuts off the decimal part.
This behaviour can result in nasty hard to catch bugs because behaviour
depends highly on server configuration.
mysql_real_escape_string() should always cast types according to MySQL
conventions which in this case means that decimal numbers should use dot
as a decimal separator regardless of the locale setting.
Test script:
---------------
mysql_connect("localhost", "root", "dev");
//English, everything is fine
setlocale(LC_ALL, 'en_US.UTF8');
var_dump(localeconv()['decimal_point']); //string(1) "."
var_dump(mysql_real_escape_string(19.9)); //string(4) "19.9"
//Slovene, (Use a locale that is installed on your system to
successfully reproduce this)
setlocale(LC_ALL, 'sl_SI.UTF8');
var_dump(localeconv()['decimal_point']); //string(1) ","
var_dump(mysql_real_escape_string(19.9)); //string(4) "19,9"
--
Edit bug report at https://bugs.php.net/bug.php?id=69348&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69348&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69348&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69348&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69348&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69348&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69348&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69348&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69348&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69348&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69348&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69348&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69348&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69348&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69348&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69348&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69348&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69348&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69348&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69348&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69348&r=mysqlcfg