|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-03-21 14:10 UTC] benjamin dot morel at gmail dot com
Description: ------------ As reported on https://externals.io/message/113521 The test script below fails because the pgsql driver seems to treat everything as PARAM_STR, despite being explicitly requested to bind the value as PARAM_INT; the "?" placeholder is therefore replaced with the string '4326' instead of the integer 4326. The problem is, in PostGIS, the ST_Transform() function has different signatures with different behaviours depending on whether the second parameter is an integer or a string. As far as I can see, because of this issue, there is no way to pass an actual integer to a function without using explicit, PostgreSQL-specific CAST syntax. I believe this is a bug and the pgsql driver should respect PDO::PARAM_STR just like the mysql driver does. Test script: --------------- $pdo = new PDO('pgsql:host=localhost;port=5432', 'postgres', 'postgres'); $statement = $pdo->prepare(" SELECT ST_AsText( ST_Transform( ST_GeomFromText('POINT(0 0)', 2154), ? ) ) "); $statement->bindValue(1, 4326, PDO::PARAM_INT); $statement->execute(); Expected result: ---------------- POINT(...) Actual result: -------------- PDOException: SQLSTATE[XX000]: Internal error: 7 ERROR: could not parse proj string '4326' PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 05:00:01 2025 UTC |
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)");