Bug #80892 [Com]: PDO::PARAM_INT is treated the same as PDO::PARAM_STR
| From: | nredon at solune dot com | Date: | Mon, 03 May 2021 08:31:04 +0000 |
| Subject: | Bug #80892 [Com]: PDO::PARAM_INT is treated the same as PDO::PARAM_STR | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233632@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80892&edit=1
ID: 80892
Comment by: nredon at solune dot 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:
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)");
Previous Comments:
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
[2021-03-24 13:21:51] mbeccati@php.net
The following pull request has been associated:
Patch Name: Fix bug #80892 PDO::PARAM_INT on pdo_pgsql
On GitHub: https://github.com/php/php-src/pull/6801
Patch: https://github.com/php/php-src/pull/6801.patch
------------------------------------------------------------------------
[2021-03-21 14:11:56] benjamin dot morel at gmail dot com
Sorry, typo. Should read:
> should respect PDO::PARAM_INT just like the mysql driver does.
------------------------------------------------------------------------
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