ID:               42322
 Updated by:       [EMAIL PROTECTED]
 Reported By:      norbert at linuxnetworks dot de
 Status:           Open
-Bug Type:         MySQL related
+Bug Type:         PDO related
 Operating System: Linux Debian Testing
 PHP Version:      5.2.3
 New Comment:

Changing category to PDO.

I don't think this is a bug.

Its hard to say what is "correct" when it comes to PDO. PDO shows many
inconsistencies when comparing different drivers. With MySQL there is no
result set to fetch after executing an INSERT statement.

Fetch is one place where the "PDO specification" states explicitly that
drivers differ in their behaviour:
"The results of this fetch are driver dependent and the data is usually
stored in the driver_data member of the pdo_stmt_t object. The ori and
offset parameters are only meaningful if the statement represents a
scrollable cursor. This function returns 1 for success or 0 in the event
of failure."
http://www.php.net/manual/en/internals2.pdo.implementing.php

As no standard behaviour has been defined, how can either MySQL or any
other driver be wrong? I guess this issue should be called a Feature
request but not a bug.

SQLite     -> no exception

MySQL      -> exception
Postgres   -> exception

Ulf


Previous Comments:
------------------------------------------------------------------------

[2007-08-16 19:21:33] norbert at linuxnetworks dot de

Description:
------------
If using the MySQL PDO driver in PDO::ERRMODE_EXCEPTION mode, calling
fetch() after executing an INSERT/UPDATE/DELETE statement throws an
exception. Instead, it should return FALSE in this case like for an
empty result set. Please compare to the SQLite PDO driver which works
correctly.

Reproduce code:
---------------
<?php

$db = new PDO( $dsn, $username, $password );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

try
{
    $db->exec("CREATE TABLE IF NOT EXISTS TestTable (id INT)");

    $sql = 'INSERT INTO TestTable VALUES ( NULL )';
    $query = $db->prepare( $sql );
    $query->execute();

    while( ( $row = $query->fetch( PDO::FETCH_ASSOC ) ) !== FALSE ) {}
    $query->closeCursor();
}
catch( PDOException $pe ) {
    echo 'Got PDOException: ' . $pe->getMessage();
}

?>

Expected result:
----------------
$query->fetch() should return FALSE, as it is not an error to call
fetch() for an INSERT statement, because it might be unknown what type
of statement will be executed (like in an SQL shell where users can
enter their custom queries).

Actual result:
--------------
PDOException


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42322&edit=1

Reply via email to