Description:
------------
When using PDO dblib, PDOStatement::execute() is returning false with a stored procedure that only contains an UPDATE statement. The procedure actually succeeds and modifies the data as expected.
I discovered this issue because we upgraded to PHP 5.3.8 from 5.3.6 using the RPMs from the Remi repository. I looked at the RPM spec file and this patch is being applied for PHP bug #50755: https://raw.github.com/remicollet/remirepo/master/php/php-5.3.7-pdo-dblib-50755.patch
According to the comments in the spec file, the patch is based off the following commits:
http://svn.php.net/viewvc?view=revision&revision=300002http://svn.php.net/viewvc?view=revision&revision=300089http://svn.php.net/viewvc?view=revision&revision=300646http://svn.php.net/viewvc?view=revision&revision=300791
Before reporting a bug to the Remi repository, I decided that I would try to duplicate the bug in PHP-trunk and I was able to.
Our environment:
MSSQL 2008
FreeTDS 0.82 (from the EPEL repo)
PHP-trunk
CentOS 5.6
Here is a simple example of the type of stored procedure that we are using.
CREATE PROCEDURE [dbo].[TestProc]
@iID integer,
@sFoo varchar(max)
AS
BEGIN
UPDATE TestTable
SET foo = @sFoo
WHERE id = @iID;
END
The stored procedure does not return any results, yet is executed successfully. PDOStatement::execute() returns false, but it returns true in vanilla PHP 5.3.8. It seems that since the procedure does not return any results, it causes PDOStatement::execute() to return false not true.
Test script:
---------------
<?php
$db = new PDO($dsn, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = 'EXEC TestProc ?, ?';
$stmt = $db->prepare($sql);
$id = 123;
$foo = 'Hello ...';
$stmt->bindParam(1, $id, PDO::PARAM_INT);
$stmt->bindParam(2, $foo, PDO::PARAM_STR);
$ret = $stmt->execute();
var_dump($ret);
?>
Expected result:
----------------
bool(true)
Actual result:
--------------
bool(false)