ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_fields:associative_key_case

This is an old revision of the document!


Associative Key Case

If returning data in associative mode, it is important to choose early in the project whether to use upper case or lower case keys. Once that decision has been made, a consistent result can be expected. ADOdb controls the casing of the keys using a constant ADODB_ASSOC_CASE.

The constant must be defined before the inclusion of the ADOdb libraries

There are 3 possible values:

Constants

NameValueDescription
ADODB_ASSOC_CASE_LOWER0lowercase field names
ADODB_ASSOC_CASE_UPPER1uppercase field names
ADODB_ASSOC_CASE_NATIVE (Default)2use native-case field names
define('ADODB_ASSOC_CASE',0);
require "adodb/adodb.inc.php";
 
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 
$sql = 'select * from some_table';
 
print_r($db->getAll($sql));
 
/*
* Returns
*
array(0=>array('col0'=>'val0',
               'col1'=>'val1',
               'col2'=>'val2',
               etc....
               )
*/

If we now set the value of ADODB_ASSOC_CASE to upper case, we obtain the following effect:

define('ADODB_ASSOC_CASE',1);
require "adodb/adodb.inc.php";
 
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 
$sql = 'select * from some_table';
 
print_r($db->getAll($sql));
 
/*
* Returns
*
array(0=>array('COL0'=>'val0',
               'COL1'=>'val1',
               'COL2'=>'val2',
               etc....
               )
*/
  • Note that setting the value of this variable has no effect on the casing of the values of the array
  • Use of ADODB_CASE_NATIVE is not recommended when writing portable applications, as there is no consistent casing across databases. Some DBMS may returned mixed-case keys.
v5/userguide/learn_fields/associative_key_case.1530479971.txt.gz · Last modified: 2018/07/01 23:19 by peterdd