php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37026 PDOStatemenet::execute() returns always false
Submitted: 2006-04-09 19:46 UTC Modified: 2006-04-09 23:55 UTC
From: kubis at pawouk dot net Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.2 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kubis at pawouk dot net
New email:
PHP Version: OS:

 

 [2006-04-09 19:46 UTC] kubis at pawouk dot net
Description:
------------
PDOStatement::execute() returns false even if the statement has been executed correctly.

I have tried it with PDO drivers for postgresql packaged with PHP version 5.1, it returns correctly true, but with version 5.2.1 it returns false. I ran into this problem while executing unit tests after an upgrade.

According to manual page should PDOStatement::execute() return true if the statement has been executed properly or false if not

Reproduce code:
---------------
try {
	$db = DBShop::getInstance();	//
	$stmt = $db->prepare('SELECT 1 AS testcolumn1, 2 AS testcolumn2');
	$count1 = $stmt->columnCount();
	$res = $stmt->execute();
	$count2 = $stmt->columnCount();
} catch (Exception $e){
	$fail[] = self::errorMsg($e, 'Unable to test columnCount()');
	break;
}
$this->assertTrue($res, 'DBStatement::execute() returned false, should be true');
$this->assertSame(2, $count2, 'DBStatement::columnCount() did not return expected value');

Expected result:
----------------
no failure in unit test:
- $res is true
- $count2 is 2

Actual result:
--------------
PHPUnit reports "DBStatement::execute() returned false, should be true", so $res is not true; but $count2 is integer of value 2, thus the statement has been executed properly

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-09 19:57 UTC] kubis at pawouk dot net
there is a typo:
sentence "but with version 5.2.1 it returns false"  should be "but with version 5.1.2 it returns false"
 [2006-04-09 23:55 UTC] edink@php.net
There is something wrong with the classes you use for testing. Short script that does not use any external sources:

<?php
$dbh = new PDO("pgsql:<conn_attrs_removed>);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare('SELECT 1 AS testcolumn1, 2 AS testcolumn2');
$count1 = $stmt->columnCount();
$res = $stmt->execute();
$count2 = $stmt->columnCount();
var_dump($res);
echo "<br>$count1<br>\n$count2";
?>

produces:

bool(true)
0
2

as it should.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC