Product Documentation

FairCom SQL for PHP

Previous Topic

Next Topic

ctsql_fetch_array

Fetches a result row as both an associative array and a numeric array.

Declaration

array ctsql_fetch_array ( resource queryID)

Description

ctsql_fetch_array() is an extended version of ctsql_fetch_row(). In addition to storing the data in the numeric indexes of the result array, it also stores the data in associative indexes, using the field names as keys.

If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use the numeric index of the column or make an alias for the column. For aliased columns, you cannot access the contents with the original column name (by using ‘field’ in the example given below).

This SELECT query demonstrates aliased duplicate field names:

SELECT table1.field AS foo, table2.field AS bar FROM table1, table2

It is important to note that while ctsql_fetch_row() may be slightly faster, ctsql_fetch_array() provides a significant added benefit for the performance difference.

Note: Field names returned by this function are case-sensitive.

Returns

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.

Example


<?php

ctsql_connect("localhost:ctreeSQL") or

die('Failed to connect to FairCom DB SQL: ' . ctsql_error());


$result = ctsql_query("SELECT id, name FROM mytable");


while ($row = ctsql_fetch_array($result)) {

printf ("ID: %s Name: %s", $row[0], $row["name"]);

}


ctsql_free_result($result);

?>


See also

ctsql_fetch_row(), ctsql_fetch_assoc().

TOCIndex