php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80521 Parameters with underscores no longer recognized
Submitted: 2020-12-15 20:37 UTC Modified: 2020-12-16 18:56 UTC
From: delmar dot delmar at gmail dot com Assigned: cmb (profile)
Status: Closed Package: PDO Firebird
PHP Version: 8.0.0 OS: Windows Pro 20H2
Private report: No CVE-ID: None
 [2020-12-15 20:37 UTC] delmar dot delmar at gmail dot com
Description:
------------
The sample code works in version 7.4.12. After upgrading to PHP 8.0.0 it stopped working.

The error message is: object (PDOException) # 3 (8) {["message": protected] => string (118) "SQLSTATE [HY000]: General error: -104 Dynamic SQL Error SQL error code = -104 Token unknown ...

PHP does not recognize the parameter COD_ALUNO =: PCOD_ALUNO in nested SQLs for derived tables (select from select).

When setting an integer for the COD_ALUNO field everything works.

https://firebirdsql.org/refdocs/langrefupd21-select.html#langrefupd21-derived-tables

Test script:
---------------
https://pastebin.com/1n32Yct4

Expected result:
----------------
As JSON

[{"CODIGO":"2118","COD_CURSO":"3","CURSO":"EDUCA\u00c7\u00c3O DE JOVENS E ADULTOS"},{"CODIGO":"977","COD_CURSO":"1","CURSO":"ENSINO FUNDAMENTAL"},{"CODIGO":"2808","COD_CURSO":"1","CURSO":"ENSINO FUNDAMENTAL"},{"CODIGO":"6555","COD_CURSO":"1","CURSO":"ENSINO FUNDAMENTAL"}]


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-15 20:43 UTC] levim@php.net
Contents of the pastebin:

<?php

$sql = ' SELECT MAT.CODIGO, MAT.COD_CURSO, MAT.CURSO FROM
                (SELECT M.CODIGO, M.COD_CURSO, C.CURSO FROM
                    (SELECT CODIGO, COD_CURSO FROM MATRICULA WHERE COD_ALUNO = :PCOD_ALUNO) AS M
                LEFT OUTER JOIN CURSO C ON M.COD_CURSO = C.CODIGO
                UNION
                SELECT ME.CODIGO, ME.COD_CURSO, C.CURSO FROM
                    (SELECT CODIGO, COD_CURSO FROM MATRICULAEJA WHERE COD_ALUNO = :PCOD_ALUNO_EJA) AS ME
                LEFT OUTER JOIN CURSO C ON ME.COD_CURSO = C.CODIGO) AS MAT
            ORDER BY MAT.CURSO';

?>
 [2020-12-15 21:14 UTC] delmar dot delmar at gmail dot com
In new tests, I noticed that the PHP 8.0.0 Firebird PDO does not accept _ in the SQL statement parameter. When removing the _ from the parameter, the code works. However, in previous versions, like 7.4.x I could use _ without problems.

If the goal is really not to accept _ in the named parameters, then this post could be closed. Otherwise, the post could remain open.

However, it is necessary to refactor all legacy SQL code where there are parameters named using _
 [2020-12-15 22:32 UTC] cmb@php.net
I think this is due to an accidental change:
<https://github.com/php/php-src/pull/4920/files#r543735101>.
 [2020-12-16 18:56 UTC] cmb@php.net
-Summary: PDO parameter in nested SQLs for derived tables +Summary: Parameters with underscores no longer recognized -Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2020-12-16 19:07 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1860ef22eba4fed1e360482cfde32b3bfa16fcc5
Log: Fix #80521: Parameters with underscores no longer recognized
 [2020-12-16 19:07 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC