php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51476 odbc_execute doesn't return proper result
Submitted: 2010-04-05 12:17 UTC Modified: 2020-10-18 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: alexeyp at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: ODBC related
PHP Version: 5.2.13 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alexeyp at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-05 12:17 UTC] alexeyp at gmail dot com
Description:
------------
Result status for odbc_execute() is not correctly returned for CREATE TABLE statements. Tested with MySQL and PostgreSQL ODBC drivers. Execution of odbc_execute() for SELECT/UPDATE/INSERT statements doesn't have that effect.

Testing CREATE TABLE with isql utility from unixODBC correctly returns an error on second execution (assuming that table didn't exist before).

Test script:
---------------
    $stmt = odbc_prepare($db, "CREATE TABLE x(id int)");
    
    if ($stmt === false) {
        $error = true;
        $resultStr = "Query: $query\nPrepare Error: " . odbc_errormsg($db);
        echo $resultStr . "\n";
    } else {
        // Executing query (if prepare went fine)
        $result = odbc_execute($stmt, $parameterArray);
        echo $resultStr . "\n";
    }
        
    if (!$result) {
        echo "ODBC Error: " . odbc_error($db) . "\n";
        $resultStr = "Query: $query\nExecute error: " . odbc_errormsg($db);
        echo $resultStr . "\n";
        $error = true;
    }

Expected result:
----------------
Execution of the test script should create table "x" during the first execution without reporting an error. The second execution should report an error.

Actual result:
--------------
Every execution of the script reports an error:

Execute error: [unixODBC]Error while executing the query (non-fatal);
ERROR:  relation "x" already exists

The table "x" is successfully created during the first test script execution.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-06 11:24 UTC] alexeyp at gmail dot com
I've added another test that clarifies the error a bit futher. The test (below) 
insert TWO records for any execution - for PostgreSQL ODBC driver. For MySQL 
driver, it's failing every second run, with not failing runs taking 2-3 seconds.

Nether effect is observed with isql utility from unixODBC (with same drivers).

Second test:
------------
<?php

    $db = @odbc_connect("DSN=PostgreSQL;Server=localhost;Database=demo", $user, 
$password);
    if (!$db) {
        echo odbc_errormsg() . "\n";
        return;
    }

    $query = "INSERT INTO t1 VALUES(2,'test',100)";

    $stmt = odbc_prepare($db, $query);
    if ($stmt === false) {
        $error = true;
        echo "Query: $query\nPrepare Error: " . odbc_errormsg($db) . "\n";
        return;
    } else {
        $result = odbc_execute($stmt, array());
    }
        
    if (!$result) {
        echo "Query: $query\nExecute error: " . odbc_errormsg($db);
        return;
    }

    echo "Ok\n";
    odbc_free_result($stmt);

?>
 [2020-10-06 15:02 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-10-06 15:02 UTC] cmb@php.net
Can you still reproduce this issue with any of the actively
supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2020-10-18 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC