[development] Extend database abstraction layer, to include table creation.

Bèr Kessels ber at webschuur.com
Fri May 12 09:42:48 UTC 2006


Op vrijdag 12 mei 2006 10:58, schreef Bèr Kessels:
> Op donderdag 11 mei 2006 20:31, schreef Adrian Rossouw:
> > http://drupal.org/node/63049
> >
> > Now that we have .install files for modules, I believe it is time we
> > extended our database abstraction layer.
> >
> > I recommend we create the following extra functions :
>
> db_fetch_all()
> This "whiling" over the db_fetch_object is driving me nuts :)

Money mouth and that stuff: 
from helpers.module (still needs testing here before I commit this)

/**
 * Returns an array with all objects from a query
 * Does not do a rewrite sql for you!
 * Call similar to db_query.
 */
function db_fetch_all_as_objects($query) {
  $results = array();
  $args = func_get_args();
  array_shift($args);
  $res = db_query($query, $args);

  while ($row = db_fetch_object($res)) {
    $results[] = $row;
  }
  return $results;
}

/**
 * Returns an array with all arrays from a query
 * Does not do a rewrite sql for you!
 * Call similar to db_query.
 */
function db_fetch_all_as_arrays($query) {
  $results = array();
  $args = func_get_args();
  array_shift($args);
  $res = db_query($query, $args);

  while ($row = db_fetch_array($res)) {
    $results[] = $row;
  }
  return $results;
}


More information about the development mailing list