Search code examples
phpadodb-php

ADOdb is returning both column names and number indexes


ADOdb fetchRow output:

Array
(
 [0] => ABC
    [NAME] => ABC
    [1] => 33
 [AGE] => 33
    [3] => M
 [GENDER] => M
    [4] => LA
 [CITY] => LA
    [5] => OH
 [STATE] => OH
)

How can I get the number-index only output:

Array 
(
 [0] => ABC
 [1] => 33
 [2] => M
 [3] => LA
 [4] => OH

) 

Or the name-index only output? :

Array
(
    [NAME] => ABC
    [AGE] => 33
    [GENDER] => M
    [CITY] => LA
    [STATE] => OH
)

Solution

    1. Numeric indexes – use $connection->SetFetchMode(ADODB_FETCH_NUM).

    2. Associative indexes – the keys of the array are the names of the fields (in upper-case). Use $connection->SetFetchMode(ADODB_FETCH_ASSOC).

    3. Both numeric and associative indexes – use $connection->SetFetchMode(ADODB_FETCH_BOTH).

    The default is ADODB_FETCH_BOTH for Oracle.