diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index cd91e68fd3e9a..e1736b76cccd3 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1950,6 +1950,11 @@ PHP_METHOD(SQLite3Result, fetchArray) SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result) + if (sqlite3_column_count(result_obj->stmt_obj->stmt) == 0) { + result_obj->complete = 1; + RETURN_FALSE; + } + ret = sqlite3_step(result_obj->stmt_obj->stmt); switch (ret) { case SQLITE_ROW: diff --git a/ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt b/ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt new file mode 100644 index 0000000000000..823d5f87dd100 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt @@ -0,0 +1,21 @@ +--TEST-- +SQLite3Result::fetchArray() test, testing non-SQLITE3_ROWS result type +--CREDITS-- +Antoni Villalonga Noceras +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE foo (bar STRING)'); + +$result = $db->query("INSERT INTO foo (bar) VALUES ('This is a test')"); + +//fetchArray should not call sqlite3_step() after an Insert, Update, etc +$result->fetchArray(SQLITE3_ASSOC); + +$result = $db->query("SELECT COUNT(*) FROM foo"); +echo $result->fetchArray(SQLITE3_NUM)[0]; +?> +--EXPECTF-- +1