From: Johannes Schlüter Date: Mon, 16 May 2011 15:37:39 +0000 (+0000) Subject: - Fix Bug #53782 (foreach throws irrelevant exception) X-Git-Tag: php-5.3.7RC1~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e17b490084ac9ffd77fd483fbb73857390166f7;p=php - Fix Bug #53782 (foreach throws irrelevant exception) --- diff --git a/NEWS b/NEWS index b78ee657ea..491c176986 100644 --- a/NEWS +++ b/NEWS @@ -85,6 +85,7 @@ PHP NEWS - PDO MySQL driver: . Fixed bug #54644 (wrong pathes in php_pdo_mysql_int.h). (Tony, Johannes) + . Fixed bug #53782 (foreach throws irrelevant exception). (Johannes, Andrey) . Implemented FR #48587 (MySQL PDO driver doesn't support SSL connections). (Rob) diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index 79694b368a..470cd0898e 100755 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -656,7 +656,11 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, #endif /* PDO_USE_MYSQLND */ if ((S->current_data = mysql_fetch_row(S->result)) == NULL) { - if (mysql_errno(S->H->server)) { +#if PDO_USE_MYSQLND + if (S->result->unbuf && !S->result->unbuf->eof_reached && mysql_errno(S->H->server)) { +#else + if (!S->result->eof && mysql_errno(S->H->server)) { +#endif pdo_mysql_error_stmt(stmt); } PDO_DBG_RETURN(0); diff --git a/ext/pdo_mysql/tests/bug53782.phpt b/ext/pdo_mysql/tests/bug53782.phpt new file mode 100644 index 0000000000..4f81cceef2 --- /dev/null +++ b/ext/pdo_mysql/tests/bug53782.phpt @@ -0,0 +1,40 @@ +--TEST-- +PDO MySQL Bug #53782 (foreach throws irrelevant exception) +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +$res = $conn->query('SELECT 0'); + +try { + $conn->query('ERROR'); +} catch (PDOException $e) { + echo "Caught: ".$e->getMessage()."\n"; +} + +foreach ($res as $k => $v) { + echo "Value: $v[0]\n"; +} + +echo "DONE"; +?> +--CLEAN-- + +--EXPECTF-- +Caught: SQLSTATE[42000]: %s +Value: 0 +DONE