diff options
author | Johannes Schlüter <johannes@php.net> | 2011-05-16 15:37:39 +0000 |
---|---|---|
committer | Johannes Schlüter <johannes@php.net> | 2011-05-16 15:37:39 +0000 |
commit | 0179c5a0e604f4b2181740fd1a0d6ed1f2a887f6 (patch) | |
tree | ce71a6cf08911c35da72dc49dd346410408735b6 | |
parent | 898e3095f14731c22f92b5863fdaa2cac5380ba8 (diff) | |
download | php-git-0179c5a0e604f4b2181740fd1a0d6ed1f2a887f6.tar.gz |
- Fix Bug #53782 (foreach throws irrelevant exception)
-rwxr-xr-x | ext/pdo_mysql/mysql_statement.c | 6 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/bug53782.phpt | 40 |
2 files changed, 45 insertions, 1 deletions
diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index 375e493930..6adba96168 100755 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -640,7 +640,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-- +<?php +if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded'); +require dirname(__FILE__) . '/config.inc'; +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +PDOTest::skip(); +?> +--FILE-- +<?php +require dirname(__FILE__) . '/config.inc'; +require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +$conn = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); + +$conn->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-- +<?php +require dirname(__FILE__) . '/mysql_pdo_test.inc'; +MySQLPDOTest::dropTestTable(); +?> +--EXPECTF-- +Caught: SQLSTATE[42000]: %s +Value: 0 +DONE |