php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56614 Failure to produce an error when one is expected
Submitted: 2005-10-25 11:28 UTC Modified: 2005-10-28 22:36 UTC
From: lists at cyberlot dot net Assigned: wez (profile)
Status: Closed Package: PDO (PECL)
PHP Version: 5_1 CVS-2005-10-25 (dev) OS: Centos 4.1
Private report: No CVE-ID: None
 [2005-10-25 11:28 UTC] lists at cyberlot dot net
Description:
------------
When not calling closeCursor after a single line select the next statement fails without error because cursor is not closed.

Reproduce code:
---------------
The following code does not insert anything, returns 00000 for the errorCode
<?php
$db = new PDO("mysql:dbname=chatbeta;host=localhost", "chatbeta", "chatbeta");
if(!$db) {
  die("DB Connection Failed");
}
$logstmt = $db->prepare('INSERT INTO logger (login, data) VALUES (:var1, :var2)');
$authstmt = $db->prepare('SELECT * FROM users WHERE login = :varlog AND password = :varpass');
$authstmt->execute(array(':varlog' => 'testing', ':varpass' => 'testing'));
print_r($authstmt->fetch());
$logstmt->execute(array(':var1' => 'test1', ':var2' => 'test2'));
print_r($db->errorCode());
?>


The following code works, same thing 00000 returned for errorcode. Only diffrence closeCursor added.
<?php
$db = new PDO("mysql:dbname=chatbeta;host=localhost", "chatbeta", "chatbeta");
if(!$db) {
  die("DB Connection Failed");
}
$logstmt = $db->prepare('INSERT INTO logger (login, data) VALUES (:var1, :var2)');
$authstmt = $db->prepare('SELECT * FROM users WHERE login = :varlog AND password = :varpass');
$authstmt->execute(array(':varlog' => 'testing', ':varpass' => 'testing'));
print_r($authstmt->fetch());
$authstmt->closeCursor();
$logstmt->execute(array(':var1' => 'test1', ':var2' => 'test2'));
print_r($db->errorCode());
?>


There is only a single line in the users table, so only one row is returned. If I change the fetch to fetchAll it works without the closeCursor.

Expected result:
----------------
Expect an error when the insert fails due to a unclosed cursor.

Actual result:
--------------
No insert of data into the database, no error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-25 12:32 UTC] wez@php.net
You should use $stmt->errorCode() for statement specific errors.
 [2005-10-25 13:37 UTC] lists at cyberlot dot net
Still no error, just 00000.

Also just noticed Im using 5.1RC1 not CVS, there is no 5.1RC1 in the new bug drop down box for versions.

Will try to pull cvs and set $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); to see if I can get further information
 [2005-10-25 14:37 UTC] lists at cyberlot dot net
Ok, downloaded php-5.1.0rc3 from the qa site.

Here is my code

<?
$db = new PDO("mysql:dbname=test;host=localhost", "test", "test");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
if(!$db) {
  die("DB Connection Failed");
}
$logstmt = $db->prepare('INSERT INTO logger (login, data) VALUES (:var1, :var2)');
$authstmt = $db->prepare('SELECT * FROM users WHERE login = :varlog AND password = :varpass');
$authstmt->execute(array(':varlog' => 'testing', ':varpass' => 'testing'));
print_r($authstmt->fetch());
$logstmt->execute(array(':var1' => 'test1', ':var2' => 'test2'));
print_r($logstmt->errorCode());
?>

Error code 00000 insert did not happen.
 [2005-10-28 22:36 UTC] wez@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 17:01:28 2024 UTC