ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:getassoc

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:connection:getassoc [2016/01/16 23:34] – ↷ Page moved from v5:reference:getassoc to v5:reference:connection:getassoc mnewnhamv5:reference:connection:getassoc [2017/05/09 01:09] (current) mnewnham
Line 14: Line 14:
 The function executes a statement and returns all of the returned rows in an array or false if the statement execution fails, or if only 1 column is requested in the SQL statement. If no records match the provided SQL statement, an empty array is returned. The function executes a statement and returns all of the returned rows in an array or false if the statement execution fails, or if only 1 column is requested in the SQL statement. If no records match the provided SQL statement, an empty array is returned.
  
-The presentation of the returned data can be modified by the variable [[v5:reference:adodb_assoc_case|$ADODB_ASSOC_CASE]].+The presentation of certain aspects of the returned data can be modified by the constant [[v5:reference:adodb_assoc_case|ADODB_ASSOC_CASE]] (see below for examples).
  
-For a detailed description of the SQL and bind parameters passed, see [[v5:reference:execute|execute()]].+For a detailed description of the SQL and bind parameters passed, see [[v5:reference:connection:execute|execute()]].
  
 In addition it should be noted that the presentation of the returned data is modified by the number of columns requested in the SQL statement and the setting of the optional parameters ''$forceArray'' and ''$first2Cols''. In addition it should be noted that the presentation of the returned data is modified by the number of columns requested in the SQL statement and the setting of the optional parameters ''$forceArray'' and ''$first2Cols''.
Line 129: Line 129:
                      
 </code> </code>
 +===== How ADODB_ASSOC_CASE affects returned data =====
 +In certain instances, the ''ADODB_ASSOC_CASE'' constant changes the casing of inner keys. **The casing of outer keys is never affected**, so in this first example, the data will always be returned as it appears in the database
 +<code php>
 +/*
 +* Connection to mysql 'employees' database assumed.
 +*/
 +$SQL = "SELECT first_name,last_name from employees";
 +$r = $db->getAssoc($SQL);
 +print_r($r);
 +/*
 +* Returns: 
 +Array
 +(
 +    [Georgi] => Wielonsky
 +    [Bezalel] => Ranon
 +    [Parto] => Kambil
 +    ........
 +)
 +*/
 +</code>
 +Setting ADODB_ASSOC_CASE to ASSOC_CASE_LOWER:
 +<code php>
 +/*
 +* Connection to mysql 'employees' database assumed.
 +*/
 +$SQL = "SELECT first_name,last_name,emp_no from employees";
 +$r = $db->getAssoc($SQL);
 +print_r($r);
 +/*
 +* Returns: 
 +Array
 +(
 +    [Georgi] => Array
 +        (
 +            [last_name] => Wielonsky
 +            [emp_no] => 499814
 +        )
 +
 +    [Bezalel] => Array
 +        (
 +            [last_name] => Ranon
 +            [emp_no] => 499846
 +        )
 +
 +    [Parto] => Array
 +        (
 +            [last_name] => Kambil
 +            [emp_no] => 499529
 +        )
 +    .......
 + )
 +*/ 
 +</code>
 +Setting ADODB_ASSOC_CASE to ASSOC_CASE_UPPER:
 +<code php>
 +/*
 +* Connection to mysql 'employees' database assumed.
 +*/
 +$SQL = "SELECT first_name,last_name,emp_no from employees";
 +$r = $db->getAssoc($SQL);
 +print_r($r);
 +/*
 +* Returns: 
 +Array
 +Array
 +(
 +    [Georgi] => Array
 +        (
 +            [LAST_NAME] => Wielonsky
 +            [EMP_NO] => 499814
 +        )
 +
 +    [Bezalel] => Array
 +        (
 +            [LAST_NAME] => Ranon
 +            [EMP_NO] => 499846
 +        )
 +
 +    [Parto] => Array
 +        (
 +            [LAST_NAME] => Kambil
 +            [EMP_NO] => 499529
 +        )
 +    .......
 + )
 +*/ 
 +</code>
 +
        
-   +===== Using The Recordset Method ===== 
 +The method can also be used as a recordset method 
 + 
 +<code php> 
 +$ar = $db->Execute("SELECT * FROM ACT")->getAssoc(); 
 +</code>    
v5/reference/connection/getassoc.1452983652.txt.gz · Last modified: 2017/04/21 11:35 (external edit)