ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_abstraction:basic_query

Differences

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

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
v5:userguide:learn_abstraction:basic_query [2016/03/15 01:15] – created mnewnhamv5:userguide:learn_abstraction:basic_query [2016/03/15 01:23] mnewnham
Line 1: Line 1:
 +<- v5:userguide:learn_abstraction:establishing_connection|Establishing A Connection ^ v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^ v5:userguide:learn_abstraction:key_value_pairs|Key/Value Pairs -> 
 +~~NOTOC~~
 ====== A Basic Query ====== ====== A Basic Query ======
 +The simplest way that ADOdb can retrieve data is through the [[v5:reference:connection:getall|getAll()]] method. This method reads the selected rows from the database into an array. Once retrieved, the data in the recordset is inserted into an array.
 +
 +<code php>
 +$sql = "select * from employees";
 +$array = $db->getAll($sql);
 +
 +print_r($array);
 +
 +/*
 +* Returns 
 +*/
 +0 => array('emp_no' => 1000,
 +           'emp_name' => 'Joe Smith',
 +           'hire_date' => '2014-01-12'
 +           ),
 +1 => array('emp_no' => 1001,
 +           'emp_name' => 'Fred Jones',
 +           'hire_date' => '2013-11-01'
 +           ),            
 +2 => array('emp_no' => 1002,
 +           'emp_name' => 'Arthur Dent',
 +           'hire_date' => '2010-09-21'
 +           ),            
 +</code>
 +
 +===== Changing How Data Is Returned =====
 +The array can be returned in one of 3 ways: numeric, associative or mixed. The example above shows the returned data in associative format. In numeric format, the same array would look like this:
 +
 +<code php>
 +0 => array(0 => 1000,
 +           1 => 'Joe Smith',
 +           2 => '2014-01-12'
 +           ),
 +1 => array(0 => 1001,
 +           1 => 'Fred Jones',
 +           2 => '2013-11-01'
 +           ),            
 +2 => array(0 => 1002,
 +           1 => 'Arthur Dent',
 +           2 => '2010-09-21'
 +           ),    
 +</code>
 +
 +For more information on setting the returned data format, see [[v5:reference:adodb_fetch_mode|$ADODB_FETCH_MODE]]
 +
 +===== Alternative Commands =====
 +There are a number of similar commands that can be used as coding shortcuts. For an exhaustive list, see the [[v5:reference:index|Reference Manual]].
  
 +^Command^Description|
 +|[[v5:reference:connection:getcol|getCol()]]|Executes a provided SQL statement and returns the first row of the entire recordset into a numeric array| 
 +|[[v5:reference:connection:getone|getOne()]]|Retrieves the first column of the first matching row of an executed SQL statement| 
 +|[[v5:reference:connection:getrow|getRow()]]|Retrieves the first matching row of an executed SQL statement|
v5/userguide/learn_abstraction/basic_query.txt · Last modified: 2016/03/15 14:27 by mnewnham