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
Next revisionBoth sides next revision
v5:reference:adodb_assoc_case [2019/05/08 13:17] – Rewrite and reformat, based also on 'Associative Key Case' page of 'Working With Fields' tutorial dregadv5:reference:adodb_assoc_case [2019/05/08 16:32] – [Possible values] reword dregad
Line 13: Line 13:
 |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',0); +define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_LOWER); 
-require "adodb/adodb.inc.php";+require "adodb.inc.php"
 +$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  
-/+// $db Connection assumed 
- * connection assumed + 
-*/+print_r($db->getAll("SELECT accountNo, accountName FROM table")); 
 + 
 +/* Response is:
  
-$sql = "SELECT accountNo,accountName FROM table"; 
-$data = $db->getAll($sql); 
-print_r($data); 
-/* 
- * Response is: 
  [0]=>array('accountno'=>1,  [0]=>array('accountno'=>1,
             'accountname'=>'The First Account'             'accountname'=>'The First Account'
Line 38: Line 39:
             'accountname'=>'The Second Account'             'accountname'=>'The Second Account'
             )             )
-            )            
- 
 */ */
 </code> </code>
Line 45: Line 44:
 or: or:
 <code php> <code php>
-define('ADODB_ASSOC_CASE',1); +define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_UPPER); 
-require "adodb/adodb.inc.php";+require "adodb.inc.php"
 +$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  
-/+// $db Connection assumed 
- * connection assumed + 
-*/+print_r($db->getAll("SELECT accountNo, accountName FROM table")); 
 + 
 +/* Response is:
  
-$sql = "SELECT accountNo,accountName FROM table"; 
-$data = $db->getAll($sql); 
-print_r($data); 
-/* 
- * Response is: 
  [0]=>array('ACCOUNTNO'=>1,  [0]=>array('ACCOUNTNO'=>1,
             'ACCOUNTNAME'=>'The First Account'             'ACCOUNTNAME'=>'The First Account'
Line 63: Line 60:
             'ACCOUNTNAME'=>'The Second Account'             'ACCOUNTNAME'=>'The Second Account'
             )             )
-            )            
- 
 */ */
 </code> </code>
Line 71: Line 66:
  
 <code php> <code php>
-define('ADODB_ASSOC_CASE',2); +define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE); 
-require "adodb/adodb.inc.php";+require "adodb.inc.php"
 +$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
  
-/+// $db Connection assumed 
- * connection assumed + 
-*/+print_r($db->getAll("SELECT accountNo, accountName FROM table")); 
 + 
 +/* Response is:
  
-$sql = "SELECT accountNo,accountName FROM table"; 
-$data = $db->getAll($sql); 
-print_r($data); 
-/* 
- * Response is: 
  [0]=>array('accountNo'=>1,  [0]=>array('accountNo'=>1,
             'accountName'=>'The First Account'             'accountName'=>'The First Account'
Line 89: Line 82:
             'accountName'=>'The Second Account'             'accountName'=>'The Second Account'
             )             )
-            )            
- 
 */ */
 </code> </code>
v5/reference/adodb_assoc_case.txt · Last modified: 2022/06/08 16:14 by dregad