ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:adodb_assoc_case

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:reference:adodb_assoc_case [2019/05/08 13:26] – Example usage: use constants instead of values, simplify code and define $ADODB_FETCH_MODE dregadv5:reference:adodb_assoc_case [2022/06/08 16:14] (current) – [Usage] fix code samples to reflect correct initialization of ADODB_ASSOC_CASE dregad
Line 4: Line 4:
 When returning data in **associative //[[v5:reference:connection:setfetchmode|fetch mode]]//**, the ''ADODB_ASSOC_CASE'' constant gives control over the casing of the retrieved recordsets' fields.  When returning data in **associative //[[v5:reference:connection:setfetchmode|fetch mode]]//**, the ''ADODB_ASSOC_CASE'' constant gives control over the casing of the retrieved recordsets' fields. 
  
-It must be declared **before** inclusion of the ADOdb libraries (''adodb.inc.php''), and being a constant it is of course not possible to change its value later on. +It must be declared **before** initializing the database connection with [[v5:reference:connection:adonewconnection|ADONewConnection()]]. 
 +Being a constantit 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. Note that this setting has no effect on the casing of the actual data.
 +
 +<WRAP info>
 +Until ADOdb 5.20.14, the documentation contained several references to a global variable named ''$ADODB_ASSOC_CASE'', which was only used in [[v5:activerecord:activerecord_index]], but in an inconsistent manner. 
 +
 +**As of 5.20.15, the only supported method to set fields case is the ''ADODB_ASSOC_CASE'' constant.**
 +</WRAP>
  
 ===== Possible values ===== ===== Possible values =====
Line 13: Line 20:
 |ADODB_ASSOC_CASE_UPPER|1|uppercase field names|  |ADODB_ASSOC_CASE_UPPER|1|uppercase field names| 
 |ADODB_ASSOC_CASE_NATIVE (Default)|2|native-case field names| |ADODB_ASSOC_CASE_NATIVE (Default)|2|native-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. 
  
 <WRAP tip> <WRAP tip>
-The default behavior, ''ADODB_CASE_NATIVE'', lets the DBMS control the fields' casing (i.e. ADOdb returns them exactly as they are defined by the DBMS). However, when writing portable code, it is strongly recommended to choose default behavior and stick to it, as there is no consistent casing across databases and some DBMS may returned mixed-case keys.+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.
 </WRAP> </WRAP>
  
 ===== Usage ===== ===== Usage =====
 <code php> <code php>
-define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_LOWER); 
 require "adodb.inc.php"; require "adodb.inc.php";
 +define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_LOWER);
 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  
-// $db Connection assumed+$db = ADONewConnection('mysql'); 
 +$db->connect($host, $user, $password, $database);
  
 print_r($db->getAll("SELECT accountNo, accountName FROM table")); print_r($db->getAll("SELECT accountNo, accountName FROM table"));
Line 40: Line 51:
  
 or: or:
 +
 <code php> <code php>
-define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_UPPER); 
 require "adodb.inc.php"; require "adodb.inc.php";
 +define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_UPPER);
 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  
-// $db Connection assumed+$db = ADONewConnection('mysql'); 
 +$db->connect($host, $user, $password, $database);
  
 print_r($db->getAll("SELECT accountNo, accountName FROM table")); print_r($db->getAll("SELECT accountNo, accountName FROM table"));
Line 63: Line 76:
  
 <code php> <code php>
-define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE); 
 require "adodb.inc.php"; require "adodb.inc.php";
 +define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE);
 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  
-// $db Connection assumed+$db = ADONewConnection('mysql'); 
 +$db->connect($host, $user, $password, $database);
  
 print_r($db->getAll("SELECT accountNo, accountName FROM table")); print_r($db->getAll("SELECT accountNo, accountName FROM table"));
v5/reference/adodb_assoc_case.1557314819.txt.gz · Last modified: 2019/05/08 13:26 by dregad