Somebody could explain me this behavior. I got this script against same query (sqlsrv_query) which return only one row with only one field (data type float)
sqlsrv_fetch($stmt);
echo sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING('UTF-8'));
sqlsrv_free_stmt($stmt);
sqlsrv_fetch($stmt);
echo sqlsrv_get_field($stmt, 0);
sqlsrv_free_stmt($stmt);
sqlsrv_fetch($stmt);
echo sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_FLOAT);
sqlsrv_free_stmt($stmt);
With this outputs
php 7.1.7, msodbc 13.1.9.0, sqlsrv 4.3.0
1.1385000000000001
1,1385
1,1385
_notice difference not only in length also in symbol_
php 7.1.5, msodbc 13.1.8.0, sqlsrv 4.2.0 preview
1.1385000000000001
1.1385
1.1385
_same length difference but not in symbol_
php 7.1.3, msodbc 13.0.0.0, sqlsrv 4.0.8
1.,1385
1,1385
1,1385
_as string it returns ., as float_
Regards
Thanks @sirio3mil for your inputs. We will definitely look into this.
@sirio3mil I forgot to ask, which platform do you use? Linux or Mac? Do you have any specific locale set?
All systems are CentOS 7 more or less updated but all version 7. Two of them are virtualized with VMware, other is a docker container.
Locale set in PHP or in CentOS?
Hi @sirio3mil , you can run locale in a terminal window in your VM and see what LANG equals to? For details, you can check here
Yes, you can also set locale from within PHP script, such as setlocale(LC_ALL, 'fr_FR.UTF-8');
I just did a brief test in Ubuntu 16 with msodbc 13.1.9 and confirmed that the floats show dots not commas when the locale is English (e.g. en_US.UTF-8). However, if the locale is French, the floats show commas instead, as it is expected.
Already makes sense for me, I did not know that these functions would return according to this parameter. The locale on those servers could be differents.
Thanks @sirio3mil . I'll now close this issue. Please feel free to reopen this.