Description
Description
This is a problem I found while investigating #12581
The behavior when using PDO::PARAM_XXX
differs depending on the driver, and also depends on the combination of parameter type and specified type. The behavior also differs depending on whether you are in emulation mode or not. The survey results are described below. I've decided that it's a bug, so I'm posting it as an issue, but if the mailing list is more appropriate, please let me know.
notes: It seems that pdo_odbc does not support emulation mode.
unspecified or PARAM_STR
DB | EMULATE | $val = null | $val = 8 | $val = '10' | $val = 'str' | $val = false |
---|---|---|---|---|---|---|
pdo_mysql | 1 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_mysql | 0 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_pgsql | 1 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_pgsql | 0 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_sqlite | 1 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_sqlite | 0 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_odbc | 1 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_odbc | 0 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
PARAM_INT
DB | EMULATE | $val = null | $val = 8 | $val = '10' | $val = 'str' | $val = false |
---|---|---|---|---|---|---|
pdo_mysql | 1 | NULL | int(8) | int(10) | int(0) | int(0) |
pdo_mysql | 0 | NULL | int(8) | string(2) "10" | string(3) "str" | int(0) |
pdo_pgsql | 1 | NULL | int(8) | int(10) | int(0) | int(0) |
pdo_pgsql | 0 | NULL | string(1) "8" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_sqlite | 1 | NULL | int(8) | int(10) | int(0) | int(0) |
pdo_sqlite | 0 | NULL | int(8) | int(10) | int(0) | int(0) |
pdo_odbc | 1 | NULL | error [*1] | error [*1] | error [*1] | error [*1] |
pdo_odbc | 0 | NULL | error [*1] | error [*1] | error [*1] | error [*1] |
[*1] SQLSTATE[HY090]: Invalid string or buffer length: [FreeTDS][SQL Server]Invalid string or buffer length (SQLExecute[0] at /php-src/ext/pdo_odbc/odbc_stmt.c:263) // my env
PARAM_BOOL
DB | EMULATE | $val = null | $val = 8 | $val = '10' | $val = 'str' | $val = false |
---|---|---|---|---|---|---|
pdo_mysql | 1 | NULL | int(1) | int(1) | int(1) | int(0) |
pdo_mysql | 0 | NULL | int(1) | string(2) "10" | string(3) "str" | int(0) |
pdo_pgsql | 1 | string(1) "f" | string(1) "t" | string(1) "t" | string(1) "t" | string(1) "f" |
pdo_pgsql | 0 | NULL | string(1) "t" | string(2) "10" | string(3) "str" | string(1) "f" |
pdo_sqlite | 1 | NULL | int(1) | int(10) | int(0) | int(0) |
pdo_sqlite | 0 | NULL | int(1) | int(10) | int(0) | int(0) |
pdo_odbc | 1 | NULL | string(1) "1" | string(2) "10" | string(3) "str" | string(0) "" |
pdo_odbc | 0 | NULL | string(1) "1" | string(2) "10" | string(3) "str" | string(0) "" |
PARAM_NULL
DB | EMULATE | $val = null | $val = 8 | $val = '10' | $val = 'str' | $val = false |
---|---|---|---|---|---|---|
pdo_mysql | 1 | NULL | NULL | NULL | NULL | NULL |
pdo_mysql | 0 | NULL | NULL | NULL | NULL | NULL |
pdo_pgsql | 1 | NULL | NULL | NULL | NULL | NULL |
pdo_pgsql | 0 | NULL | NULL | NULL | NULL | NULL |
pdo_sqlite | 1 | NULL | NULL | NULL | NULL | NULL |
pdo_sqlite | 0 | NULL | NULL | NULL | NULL | NULL |
pdo_odbc | 1 | NULL | NULL | NULL | NULL | NULL |
pdo_odbc | 0 | NULL | NULL | NULL | NULL | NULL |
I would like to make the behavior consistent, but what do you think of the following rules?
- (Highest priority) If the parameter or type specification is NULL, pass NULL
- (Otherwise) Pass the value by casting to the specified type
....What is this argument for in the first place?
Regards.
PHP Version
any
Operating System
any