php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33707 Errors in select statements not reported
Submitted: 2005-07-14 22:07 UTC Modified: 2005-09-10 23:38 UTC
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: mangst at inventec dot ch Assigned: wez (profile)
Status: Closed Package: PDO related
PHP Version: 5CVS-2005-07-14 (dev) OS: Windows 2000
Private report: No CVE-ID: None
 [2005-07-14 22:07 UTC] mangst at inventec dot ch
Description:
------------
When a SQL statement is executed with PDO::query, PDO::errorInfo[0] always reports "00000" even when an error has occurred and PDO::query returned <false>.

Reproduce code:
---------------
<?php
    try {
        $db = new PDO('oci:dbname=***', '***', '***');
    } catch (PDOException $e) {
        exit ("Failed to obtain db handle: " . $e->getMessage());
    }
    $rs = $db->query('select nvarchar(8) from dual');
    echo 'Statement handle: ';
    var_dump($rs);
    echo "<br />\r\nError info of database handle: ";
    var_dump($db->errorInfo());
    $db = null;
?>

Expected result:
----------------
Somthing like:
Statement handle: bool(false)
Error info of database handle: array(1) { [0]=> string(5) "42000" [1]=> "????" [2]=> string(x) "ORA-00904: "NVARCHAR": invalid identifier"}

Actual result:
--------------
Statement handle: bool(false)
Error info of database handle: array(1) { [0]=> string(5) "00000" }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-14 23:37 UTC] tony2001@php.net
That happens because Oracle's OCIStmtPrepare() doesn't validate the query, it just allocates/prepares stmt handle for execution. Then PDO happily executes this statement and all errors go to the stmt handle (which is destroyed right after that).
Wez, from what I can see, with OCI we should always copy einfo struct from the stmt handle to the dbh handle if stmt's execution failed.
Thoughts?
 [2005-07-14 23:58 UTC] wez@php.net
I don't view this as a bug.  We report errors when the driver tells us there are errors; PDO isn't doing anything wrong, per se.

I also don't see how copying the errors up from the statement to the dbh when execute() is called will help either.

 [2005-07-15 08:20 UTC] tony2001@php.net
>I don't view this as a bug. 
You can't reproduce it? I can.

>We report errors when the driver tells us there are errors;
> PDO isn't doing anything wrong, per se.
But there was an error, it's just hidden.
This code works fine:
<?php
$db = new PDO('oci:dbname=..', '..', '..');
$st = $db->prepare('select blah from dual');
$rs = $st->execute();
    
var_dump($rs);
var_dump($st->errorInfo());
?>

And this doesn't (only with OCI):
<?php
$db = new PDO('oci:dbname=..', '..', '..');
$rs = $db->query('select blah from dual');

var_dump($rs);
var_dump($db->errorInfo());
?>
This happens because with MySQL it fails on prepare stage, but OCI passes prepare and fails only while executing the statement, so the error goes to the statement handle. 
 [2005-07-15 13:07 UTC] wez@php.net
Ah, I misread the report. PDO::query() should report an error here of course.
 [2005-09-10 23:38 UTC] wez@php.net
Fixed on the tip of the 5.1 branch.
 [2021-02-26 11:29 UTC] sabrinagilbe at gmail dot com
Thanks for the info i will try to figure it out for more      


https://www.krogerfeed.us/
 [2024-07-30 06:32 UTC] lawleitl22 at gmail dot com
Nice post! I learned a lot from this.
Thanks for sharing this!

(https://github.com.php/)(https://spotsurv.com/mykfcexperience-sharing-your-kfc-experience/)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 05:01:29 2024 UTC