waDbResultSelect

Formatted output of SQL SELECT queries

Contents...

An instance of this class is returned by methods of waModel class when SQL SELECT queries are executed.

Methods

public function count()

Returns the number of found database records.

Example

$model = new waModel();
$model->query('SELECT * FROM table_name')->count();

public function fetch()

Returns the contents of the first found record as a combination of a zero-indexed and associative array.

Example

$model = new waModel();
$model->query('SELECT * FROM table_name')->fetch();

Result

Array
(
  0    => '1'
  id   => '1'
  1    => 'John'
  name => 'John'
  2    => '25'
  age  => '25'
)

public function fetchAll ($key = null, $normalize = false)

Returns the contents of all found database records as an array of sub-arrays corresponding to individual records. The use of parameters is identical to that described for method getAll of class waModel.

public function fetchArray()

Returns the contents of the first found record as a zero-indexed array.

Example

$model = new waModel();
$model->query('SELECT * FROM table_name')->fetchArray();

Result

Array
(
  0 => '1'
  1 => 'John'
  2 => '25'
)

public function fetchAssoc()

Returns the contents of the first found record as an associative array.

$model = new waModel();
$model->query('SELECT * FROM table_name')->fetchAssoc();

Result

Array
(
  id   => '1'
  name => 'John'
  age  => '25'
)

public function fetchField ($field = false, $seek = false)

Returns the value of the specified field in the first found record.

Parameters

Example

$model = new waModel();
$result = $model->query('SELECT * FROM table_name');
$result->fetchField('name', true); //'John'
$result->fetchField('name', true); //'Mary'
$result->fetchField('name', true); //'Bill'
//each call of the method returns the field value of the next found daatbase record if $seek is set to true