Bug #80892 [PATCH]: PDO::PARAM_INT is treated the same as PDO::PARAM_STR
Edit report at https://bugs.php.net/bug.php?id=80892&edit=1
ID: 80892
Patch added by: vivo50lte@yahoo.com
Reported by: benjamin dot morel at gmail dot com
Summary: PDO::PARAM_INT is treated the same as PDO::PARAM_STR
Status: Re-Opened
Type: Bug
Package: PDO PgSQL
Operating System: Linux
PHP Version: 8.0.3
Assigned To: mbeccati
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: Add commit ID to build info
On GitHub: https://github.com/php/doc-base/pull/17
Patch: https://github.com/php/doc-base/pull/17.patch
Previous Comments:
------------------------------------------------------------------------
[2021-05-03 08:46:16] mbeccati@php.net
Thanks nredon at solune dot com for the feedback. That indicates that fixing this bug would
potentially be not viable for 8.1 too.
------------------------------------------------------------------------
[2021-05-03 08:31:04] nredon at solune dot com
A regression occurs with smallint datatype with PostgreSQL.
PLSQL Function :
----------------
CREATE OR REPLACE FUNCTION public.check_int_param(param_int integer) RETURNS text AS
$BODY$BEGIN
RETURN param_int::text;
END;$BODY$
LANGUAGE plpgsql VOLATILE NOT LEAKPROOF
COST 100;
CREATE OR REPLACE FUNCTION public.check_smallint_param(param_smallint smallint) RETURNS text AS
$BODY$BEGIN
RETURN param_smallint::text;
END;$BODY$
LANGUAGE plpgsql VOLATILE NOT LEAKPROOF
COST 100;
PHP Test script :
----------------
$pdo = new PDO('pgsql:host=127.0.0.1;port=5432;dbname=test_php', 'postgres',
'postgres');
$val_test = 1234;
$statement = $pdo->prepare("SELECT check_int_param(:param1)"); //Integer datatype : OK
$statement->bindParam(':param1', $val_test, PDO::PARAM_INT);
$statement->execute();
$res = $statement->fetch(\PDO::FETCH_ASSOC);
var_dump($res);
// array(1) { ["check_int_param"]=> string(4) "1234" }
$statement = $pdo->prepare("SELECT check_smallint_param(:param1)"); //Smallint datatype
was OK in PHP 7.3.3 but not anymore.
$statement->bindParam(':param1', $val_test, PDO::PARAM_INT); //No PDO::PARAM_SMALLINT
available
$statement->execute();
$res = $statement->fetch(\PDO::FETCH_ASSOC);
var_dump($res);
//Fatal error: Uncaught PDOException: SQLSTATE[42883]: Undefined function: 7 ERROR: function
check_smallint_param(integer) does not exist LINE 1: SELECT check_smallint_param($1) ^ HINT: No
function matches the given name and argument types. You might need to add explicit type casts.
Expected result:
----------------
// array(1) { ["check_int_param"]=> string(4) "1234" }
Workaround :
----------------
$statement = $pdo->prepare("SELECT check_smallint_param(:param1::smallint)");
------------------------------------------------------------------------
[2021-04-30 11:14:25] cmb@php.net
Related To: Bug #81002
------------------------------------------------------------------------
[2021-04-29 10:09:46] mbeccati@php.net
Unfortunately the fix led to a fairly significant behaviour change. It has been decided to revert
the change and leave the fix for later, possibly 8.1+ only.
------------------------------------------------------------------------
[2021-04-12 06:23:06] git@php.net
Automatic comment on behalf of mbeccati
Revision: https://github.com/php/php-src/commit/340a06778c39054c7d715bceab82175840d92443
Log: Fix #80892: PDO::PARAM_INT is treated the same as PDO::PARAM_STR
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=80892
--
Edit this bug report at https://bugs.php.net/bug.php?id=80892&edit=1
Thread (8 messages)