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
Last revisionBoth sides next revision
reference:adodb_assoc_case [2015/12/04 15:53] – [ADODB_ASSOC_CASE] mnewnhamv5:reference:adodb_assoc_case [2022/06/08 16:10] – [ADODB_ASSOC_CASE] fix incorrect indication of when constant must be declared dregad
Line 1: Line 1:
-====== ADODB_ASSOC_CASE =====+====== ADODB_ASSOC_CASE ======
 ~~NOTOC~~ ~~NOTOC~~
-<WRAP right info 300px> 
-== See Also == 
-[[dictionary:setmetacaseoption|metaCasing]] 
-</WRAP> 
-The constant must be declared **before** including  adodb.inc.php. 
  
-You can control the associative fetch case for certain drivers which behave differently. For the following drivers: +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. 
  
-  * [[database:sap_ase|sybase]] +It must be declared **before** initializing the database connection with [[v5:reference:connection:adonewconnection|ADONewConnection()]]. 
-  * [[database:oracle]],  +Being a constantit is of course not possible to change its value later on. 
-  [[database:microsoft_sql_server]], + 
-  * [[database:odbc]]  +Note that this setting has no effect on the casing of the actual data. 
-  [[database:ibase]]  + 
-  all drivers derived from those above, +<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.  
-ADODB_ASSOC_CASE will by default generate recordsets where the field name keys are lower-cased. Use the constant ADODB_ASSOC_CASE to change the case of the keysThere are 3 possible values:+ 
 +**As of 5.20.15, the only supported method to set fields case is the ''ADODB_ASSOC_CASE'' constant.** 
 +</WRAP>
  
-===== Constants =====+===== Possible values =====
 ^Name^Value^Description^ ^Name^Value^Description^
 |ADODB_ASSOC_CASE_LOWER|0|lowercase field names| |ADODB_ASSOC_CASE_LOWER|0|lowercase field names|
 |ADODB_ASSOC_CASE_UPPER|1|uppercase field names|  |ADODB_ASSOC_CASE_UPPER|1|uppercase field names| 
-|ADODB_ASSOC_CASE_NATIVE (Default)|2|use 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> 
 +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>
  
 ===== 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 44: Line 46:
             'accountname'=>'The Second Account'             'accountname'=>'The Second Account'
             )             )
-            )            
- 
 */ */
 </code> </code>
Line 51: Line 51:
 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 69: Line 67:
             'ACCOUNTNAME'=>'The Second Account'             'ACCOUNTNAME'=>'The Second Account'
             )             )
-            )            
- 
 */ */
 </code> </code>
Line 77: Line 73:
  
 <code php> <code php>
-DEFINE(ADODB_ASSOC_CASE,3); +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 95: Line 89:
             '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