|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-04-01 18:50 UTC] stas@php.net
-Status: Open
+Status: Not a bug
[2015-04-01 18:50 UTC] stas@php.net
[2017-09-22 18:57 UTC] seb35 at seb35 dot fr
[2017-09-22 19:11 UTC] mdrolc at gmail dot com
[2017-09-22 19:14 UTC] spam2 at rhsoft dot net
[2017-09-22 19:58 UTC] seb35 at seb35 dot fr
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 22:00:01 2025 UTC |
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"