ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:adodb_assoc_case

ADODB_ASSOC_CASE

When returning data in associative fetch mode, the ADODB_ASSOC_CASE constant gives control over the casing of the retrieved recordsets' fields.

It must be declared before initializing the database connection with ADONewConnection(). Being a constant, it is of course not possible to change its value later on.

Note that this setting has no effect on the casing of the actual data.

Until ADOdb 5.20.14, the documentation contained several references to a global variable named $ADODB_ASSOC_CASE, which was only used in ADOdb Active Record, but in an inconsistent manner.

As of 5.20.15, the only supported method to set fields case is the ADODB_ASSOC_CASE constant.

Possible values

NameValueDescription
ADODB_ASSOC_CASE_LOWER0lowercase field names
ADODB_ASSOC_CASE_UPPER1uppercase field names
ADODB_ASSOC_CASE_NATIVE (Default)2native-case field names

With the default behavior, ADODB_ASSOC_CASE_NATIVE, ADOdb does not perform any transformation on field names, and returns them exactly as they are defined by the DBMS.

When writing portable code, it is strongly recommended to choose either upper or lower case. Relying on the native case default will likely cause compatibility issues, as there is no consistent casing across databases and some DBMS may returned mixed-case keys.

Usage

require "adodb.inc.php";
define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_LOWER);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 
$db = ADONewConnection('mysql');
$db->connect($host, $user, $password, $database);
 
print_r($db->getAll("SELECT accountNo, accountName FROM table"));
 
/* Response is:
 
 [0]=>array('accountno'=>1,
            'accountname'=>'The First Account'
            ),
 [1]=>array('accountno'=>2,
            'accountname'=>'The Second Account'
            )
*/

or:

require "adodb.inc.php";
define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_UPPER);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 
$db = ADONewConnection('mysql');
$db->connect($host, $user, $password, $database);
 
print_r($db->getAll("SELECT accountNo, accountName FROM table"));
 
/* Response is:
 
 [0]=>array('ACCOUNTNO'=>1,
            'ACCOUNTNAME'=>'The First Account'
            ),
 [1]=>array('ACCOUNTNO'=>2,
            'ACCOUNTNAME'=>'The Second Account'
            )
*/

or:

require "adodb.inc.php";
define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
 
$db = ADONewConnection('mysql');
$db->connect($host, $user, $password, $database);
 
print_r($db->getAll("SELECT accountNo, accountName FROM table"));
 
/* Response is:
 
 [0]=>array('accountNo'=>1,
            'accountName'=>'The First Account'
            ),
 [1]=>array('accountNo'=>2,
            'accountName'=>'The Second Account'
            )
*/
v5/reference/adodb_assoc_case.txt · Last modified: 2022/06/08 16:14 by dregad