php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77118 PDOStatement::fetchColumn() of a non-existing column triggers a warning
Submitted: 2018-11-07 20:22 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: morozov at tut dot by Assigned:
Status: Open Package: PDO OCI
PHP Version: 7.2.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
25 - 15 = ?
Subscribe to this entry?

 
 [2018-11-07 20:22 UTC] morozov at tut dot by
Description:
------------
When an invalid column number is provided to PDOStatement::fetchColumn(), MySQL, PostgreSQL and SQLite drivers return NULL without triggering a warning.

Unlike the above, the Oracle driver triggers a misleading warning: column %d data was too large for buffer and was truncated to fit it.

Test script:
---------------
$conn = new PDO('oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)))', 'system', 'oracle');

// incorrect column, positional parameter
$stmt = $conn->prepare('SELECT ? FROM DUAL');
$stmt->execute([1]);
$value = $stmt->fetchColumn(1);
var_dump($value);

Expected result:
----------------
NULL

Actual result:
--------------
NULL

Warning: PDOStatement::fetchColumn(): column 1 data was too large for buffer and was truncated to fit it in test.php on line 20

Call Stack:
    0.0001     365728   1. {main}() test.php:0
    0.0189     372584   2. PDOStatement->fetchColumn() test.php:20



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-12 22:27 UTC] v-yitam at microsoft dot com
I found another issue also related to PDOStatement::fetchColumn() with an invalid column number, as described in 
https://github.com/Microsoft/msphpsql/issues/968

When PDO::ATTR_ERRMODE is set to PDO::ERRMODE_EXCEPTION, the error message is meaningless, but if error mode is warning or silent, the error message is actually more helpful.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 16:01:27 2019 UTC