PHP Function pg_num_Fields - Retrieving Column Names From PostgreSQL Databases
php function pg_num_fields is one of the most useful functions for retrieving column names from PostgreSQL databases. This article covers how to use this function and some tips for writing effective php code.
There are many other useful php functions for PostgreSQL work. Some of these include pg_field_name(), which returns the name of the field occupying row number (column index) in a given query result set; pg_field_prtlen(), which returns the actual printed length (number of characters) of a field or column value in a PostgreSQL result; pg_fetch_all(), which returns an array that contains all rows (tuples/records) in a given PostgreSQL query result resource; and pg_parameter_status(), which looks up current parameter settings on a server.
When writing a php script, it's important to remember that variables can be passed by reference or by value. Passing by reference means that a new entry is added to the PHP symbol table, which references an internal data structure that holds the variable type and value. Passing by value, on the other hand, simply passes a copy of the variable to the function.
To help prevent passing by reference, a new PHP feature was introduced in PHP 7.0 called PHP_AUTO_SCOPE_BY_VALUE. This automatically scopes a variable in the function to its arguments, preventing variables from being used outside of the function definition. To enable this, add a colon (:) right before the opening curly bracket of your function definition. Note that PHP 7.1 supports PHP_AUTO_SCOPE_BY_VALUE even without this feature enabled.