msphpsql icon indicating copy to clipboard operation
msphpsql copied to clipboard

bigint column return as string with pdo

Open NVD-R opened this issue 6 years ago • 4 comments

PHP Driver version or file name

5.8

SQL Server version

18.4

Client operating system

win 10

PHP version

7.3

Microsoft ODBC Driver version

2.3.7

Table schema

a table with bigint column

Problem description

bigint column return as string, i use SQLSRV_ATTR_FETCHES_NUMERIC_TYPE but problem still exist!

Expected behavior and actual behavior

expected return bigint column as integer

Repro code or steps to reproduce

NVD-R avatar Feb 25 '20 16:02 NVD-R

@NVD-R This is by design. Since PHP's integer type is platform-dependent, it may not be wide enough for SQL Server's bigint type, so any bigint fields are returned as strings to avoid loss of data. See the table of default PHP types; also note that the documentation for SQLSRV_ATTR_FETCHES_NUMERIC_TYPE does not list bigints, only smaller types and floats.

david-puglielli avatar Feb 25 '20 19:02 david-puglielli

@NVD-R closing this issue now as we have answered your questions. Please feel free to reopen if necessary.

yitam avatar Mar 04 '20 00:03 yitam

Is there any possibity that this will be changed in the future? Even if it's a configurable option. PHP running on 64-bit systems (I assume the vast majority are) can support bigint to PHP int conversions so does it not make sense to allow this as a default PHP type?

Thank you

startork avatar Jan 18 '24 11:01 startork

Worse, I've observed inconsistent behaviour where some systems seem to get the real integer through but others don't running the exact same code? Looks like there's been multiple attempts to PR this fix in but none successful so far.

jameswilddev avatar Feb 26 '25 17:02 jameswilddev