0

I've searched everywhere and although I've found some close answers here and in the documentation, I'm unable to apply it to them to my situation.

Perhaps someone could be kind enough to help me to convert the following to the adodb way of doing things?

foreach ($rs as $field => $value) {
  $$field=stripslashes($value);
}
$rs->Close();

This is my latest attempt,

while (!$rs->EOF) {
  for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++){

    $$rs->fields($i) = $rs->fields[$i];
  }
  $rs->MoveNext();
}

The general idea is that $rs should have obtained a single record (due to the WHERE clause only matching one record), containing multiple columns/fields.

I wish to assign each of those fields to a variable of the same name as the field.

I have tried many different configurations and alternatives of the above, including ADODB_FETCH_BOTH ADODB_FETCH_NUM & ADODB_FETCH_ASSOC but still can't get it to work.

This is a similar question but I'm unable to apply it's answer. Much appreciated.

Community
  • 1
  • 1
Peter White
  • 1,016
  • 2
  • 14
  • 29

1 Answers1

0

I've found the answer, or at least the following worked for me.

This item in the manual provided information about FetchField, which I was previously unaware of and from that, I was able to figure out what to do.

while (!$rs->EOF) {
  for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
    $fld    = $rs->FetchField($i);
    $name   = $fld->name;
    $$name  = stripslashes($rs->fields[$i]);
  }
  $rs->MoveNext();
}

I tested this with connection types, ADODB_FETCH_ASSOC, ADODB_FETCH_NUM, & ADODB_FETCH_BOTH and 'BOTH' is the only type which works for me.

Peter White
  • 1,016
  • 2
  • 14
  • 29