diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2005-07-08 00:40:32 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2005-07-08 00:40:32 +0000 |
commit | ef7bd06657b0850d4b1c507c2ef6af88fb79cd03 (patch) | |
tree | a905bc4ec5c638c62e4f0697bea0fd564fe11597 /ext | |
parent | 71d28a82cf9571619a7a2ef1ff2e1c75307b6757 (diff) | |
download | php-git-ef7bd06657b0850d4b1c507c2ef6af88fb79cd03.tar.gz |
Added pg_fetch_all_columns() function to fetch all values of a column from
a result cursor.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pgsql/pgsql.c | 42 | ||||
-rw-r--r-- | ext/pgsql/php_pgsql.h | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 61cd217578..19e58f67c5 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -127,6 +127,7 @@ function_entry pgsql_functions[] = { PHP_FE(pg_fetch_array, NULL) PHP_FE(pg_fetch_object, NULL) PHP_FE(pg_fetch_all, NULL) + PHP_FE(pg_fetch_all_columns, NULL) #if HAVE_PQCMDTUPLES PHP_FE(pg_affected_rows,NULL) #endif @@ -2101,6 +2102,47 @@ PHP_FUNCTION(pg_fetch_all) } /* }}} */ +/* {{{ proto array pg_fetch_all_columns(resource result [, int column_number]) + Fetch all rows into array */ +PHP_FUNCTION(pg_fetch_all_columns) +{ + zval *result; + PGresult *pgsql_result; + pgsql_result_handle *pg_result; + long colno=0; + int pg_numrows, pg_row; + size_t num_fields; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &result, &colno) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); + + pgsql_result = pg_result->result; + + num_fields = PQnfields(pgsql_result); + if (colno >= num_fields || colno < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid column number '%ld'", colno); + RETURN_FALSE; + } + + array_init(return_value); + + if ((pg_numrows = PQntuples(pgsql_result)) <= 0) { + return; + } + + for (pg_row = 0; pg_row < pg_numrows; pg_row++) { + if (PQgetisnull(pgsql_result, pg_row, colno)) { + add_next_index_null(return_value); + } else { + add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); + } + } +} +/* }}} */ + /* {{{ proto bool pg_result_seek(resource result, int offset) Set internal row offset */ PHP_FUNCTION(pg_result_seek) diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index 21f9ecde09..78c1cb541d 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -107,6 +107,7 @@ PHP_FUNCTION(pg_fetch_object); PHP_FUNCTION(pg_fetch_result); PHP_FUNCTION(pg_fetch_row); PHP_FUNCTION(pg_fetch_all); +PHP_FUNCTION(pg_fetch_all_columns); #if HAVE_PQCMDTUPLES PHP_FUNCTION(pg_affected_rows); #endif |