v5:userguide:learn_abstraction:basic_query
This is an old revision of the document!
A Basic Query
The simplest way that ADOdb can retrieve data is through the 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.
$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' ),
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:
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' ),
For more information on setting the returned data format, see $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 Reference Manual.
v5/userguide/learn_abstraction/basic_query.1458001409.txt.gz · Last modified: 2017/04/21 11:40 (external edit)