Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pg_fetch_array(3) [php man page]

PG_FETCH_ARRAY(3)														 PG_FETCH_ARRAY(3)

pg_fetch_array - Fetch a row as an array

SYNOPSIS
array pg_fetch_array (resource $result, [int $row], [int $result_type = PGSQL_BOTH]) DESCRIPTION
pg_fetch_array(3) returns an array that corresponds to the fetched row (record). pg_fetch_array(3) is an extended version of pg_fetch_row(3). In addition to storing the data in the numeric indices (field number) to the result array, it can also store the data using associative indices (field name). It stores both indicies by default. Note This function sets NULL fields to the PHP NULL value. pg_fetch_array(3) is NOT significantly slower than using pg_fetch_row(3), and is significantly easier to use. PARAMETERS
o $result - PostgreSQL query result resource, returned by pg_query(3), pg_query_params(3) or pg_execute(3) (among others). o $row - Row number in result to fetch. Rows are numbered from 0 upwards. If omitted or NULL, the next row is fetched. o $result_type - An optional parameter that controls how the returned array is indexed. $result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM and PGSQL_BOTH. Using PGSQL_NUM, pg_fetch_array(3) will return an array with numerical indices, using PGSQL_ASSOC it will return only associative indices while PGSQL_BOTH, the default, will return both numerical and associa- tive indices. RETURN VALUES
An array indexed numerically (beginning with 0) or associatively (indexed by field name), or both. Each value in the array is represented as a string. Database NULL values are returned as NULL. FALSE is returned if $row exceeds the number of rows in the set, there are no more rows, or on any other error. EXAMPLES
Example #1 pg_fetch_array(3) example <?php $conn = pg_pconnect("dbname=publisher"); if (!$conn) { echo "An error occurred. "; exit; } $result = pg_query($conn, "SELECT author, email FROM authors"); if (!$result) { echo "An error occurred. "; exit; } $arr = pg_fetch_array($result, 0, PGSQL_NUM); echo $arr[0] . " <- Row 1 Author "; echo $arr[1] . " <- Row 1 E-mail "; // As of PHP 4.1.0, the row parameter is optional; NULL can be passed instead, // to pass a result_type. Successive calls to pg_fetch_array will return the // next row. $arr = pg_fetch_array($result, NULL, PGSQL_ASSOC); echo $arr["author"] . " <- Row 2 Author "; echo $arr["email"] . " <- Row 2 E-mail "; $arr = pg_fetch_array($result); echo $arr["author"] . " <- Row 3 Author "; echo $arr[1] . " <- Row 3 E-mail "; ?> SEE ALSO
pg_fetch_row(3), pg_fetch_object(3), pg_fetch_result(3). PHP Documentation Group PG_FETCH_ARRAY(3)

Check Out this Related Man Page

SQLITE_FETCH_ARRAY(3)													     SQLITE_FETCH_ARRAY(3)

sqlite_fetch_array - Fetches the next row from a result set as an array

SYNOPSIS
array sqlite_fetch_array (resource $result, [int $result_type = SQLITE_BOTH], [bool $decode_binary = true]) DESCRIPTION
Object oriented style (method): array SQLiteResult::fetch ([int $result_type = SQLITE_BOTH], [bool $decode_binary = true]) array SQLiteUnbuffered::fetch ([int $result_type = SQLITE_BOTH], [bool $decode_binary = true]) Fetches the next row from the given $result handle. If there are no more rows, returns FALSE, otherwise returns an associative array rep- resenting the row data. PARAMETERS
o $result - The SQLite result resource. This parameter is not required when using the object-oriented method. o $result_type -The optional $result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_BOTH will return both associative and numerical indices. SQLITE_BOTH is the default for this function. o $decode_binary -When the $decode_binary parameter is set to TRUE (the default), PHP will decode the binary encoding it applied to the data if it was encoded using the sqlite_escape_string(3). You should normally leave this value at its default, unless you are interoperating with databases created by other sqlite capable applications. RETURN VALUES
Returns an array of the next row from a result set; FALSE if the next position is beyond the final row. The column names returned by SQLITE_ASSOC and SQLITE_BOTH will be case-folded according to the value of the sqlite.assoc_case configuration option. EXAMPLES
Example #1 Procedural example <?php $dbhandle = sqlite_open('sqlitedb'); $query = sqlite_query($dbhandle, 'SELECT name, email FROM users LIMIT 25'); while ($entry = sqlite_fetch_array($query, SQLITE_ASSOC)) { echo 'Name: ' . $entry['name'] . ' E-mail: ' . $entry['email']; } ?> Example #2 Object-oriented example <?php $dbhandle = new SQLiteDatabase('sqlitedb'); $query = $dbhandle->query('SELECT name, email FROM users LIMIT 25'); // buffered result set $query = $dbhandle->unbufferedQuery('SELECT name, email FROM users LIMIT 25'); // unbuffered result set while ($entry = $query->fetch(SQLITE_ASSOC)) { echo 'Name: ' . $entry['name'] . ' E-mail: ' . $entry['email']; } ?> SEE ALSO
sqlite_array_query(3), sqlite_fetch_string(3). PHP Documentation Group SQLITE_FETCH_ARRAY(3)
Man Page