note 27263 added to function.odbc-fetch-row
| From: | alex at bartl dot net | Date: | Fri, 29 Nov 2002 15:22:11 +0000 |
| Subject: | note 27263 added to function.odbc-fetch-row | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40116@lists.php.net to get a copy of this message | ||
/*
I found the combination of the following lines very useful, as the
fieldnames will be simply available as variables by their names.
$query="select fieldname from table";
...
$line=mysql_fetch_assoc($query_result);
extract($line);
echo $fieldname;
However, I was missing the function odbc_fetch_assoc() so I created it myself to use in in the same
way like mysql_fetch_assoc(). I am sure it could be coded in a better way, but at least it works.
As a side effect $odbc_affected_rows should contain the amount of rows found, but have a look at
odbc_num_rows() as well, as in my case it does not contain the expected information.
array obdc_fetch_assoc(resource result)
*/
function odbc_fetch_assoc($rs){
if (odbc_fetch_row($rs)){
$line=array("odbc_affected_rows"=>odbc_num_rows($rs));
for($f=1;$f<=odbc_num_fields($rs);$f++){
$fn=odbc_field_name($rs,$f);
$fct=odbc_result($rs,$fn);
$newline=array($fn => $fct);
$line=array_merge($line,$newline);
//echo $f.": ".$fn."=".$fct."<br>";
}
return $line;
}
else{
return false;
}
}
--
http://www.php.net/manual/en/function.odbc-fetch-row.php
http://master.php.net/manage/user-notes.php?action=edit+27263
http://master.php.net/manage/user-notes.php?action=delete+27263
http://master.php.net/manage/user-notes.php?action=reject+27263