sql_allfetsel

The sql_allfetsel() functions retrieves an array with all of the results of a selection. It accepts the same parameters as the sql_select() function and is a combined short-cut to replace calling sql_select() and sql_fetch_all(). As it stores all of the results in a PHP array, be careful not to exceed the memory limit allowed to PHP if you are dealing with large data volumes.

It accepts 9 parameters:

  1. $select,
  2. $from,
  3. $where,
  4. $groupby,
  5. $orderby,
  6. $limit,
  7. $having,
  8. $serveur,
  9. $option.

The sql_allfetsel() function is used as shown below:

$all = sql_allfetsel('column', 'table');
// $all[0]['column'] is the column in the first line retrieved

Example

Select all of the objet / id_objet pairs associated with a particular document:

if ($liens = sql_allfetsel('objet, id_objet', 'spip_documents_liens', 'id_document=' . intval($id))) {
	foreach ($liens as $l) {
		// $l['objet'] and $l['id_objet']
	}
}

The "Contact avancé" plugin selects all of the emails for the recipients of a message as shown below:

// Retrieve who it was sent to
$destinataire = _request('destinataire');
if (!is_array($destinataire)) {
	$destinataire = array($destinataire);
}
$destinataire = array_map('intval', $destinataire);
$mail = sql_allfetsel('email', 'spip_auteurs', sql_in('id_auteur', $destinataire));

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français