note 12995 deleted from function.odbc-fetch-row by danbrown
| From: | danbrown@php.net | Date: | Fri, 25 Jun 2010 15:19:04 +0000 |
| Subject: | note 12995 deleted from function.odbc-fetch-row by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170447@lists.php.net to get a copy of this message | ||
Note Submitter: mchelen2 at hknet dot com
----
I used to PHP's mysql functions. Now there is a project that I need to use PHP with IBM DB2.
So, I have to use PHP's ODBC functions. However, the ODBC functions are different from Mysql
functions. And, missing the "mysql_fetch_object()" function. I used to the
"mysql_fetch_object()". So, I want to have "odbc_fetch_object()" too.
So, I come up with the following function.
class fetch_object{
function fetch($re){
$no_r = odbc_num_rows($re);
$no_f = odbc_num_fields ($re);
if (odbc_fetch_row($re)){
for ($i=1;$i<=$no_f;$i++){
$fn = odbc_field_name ($re, $i);
$f_re = odbc_result($re, $i);
$ff = "\$this->".$fn."='".$f_re."';";
eval($ff);
}
}
}
}
function odbc_fetch_object($result){
$good = new fetch_object;
$good->fetch($result);
return $good;
}
You can use this function 100% the same way as 'mysql_fetch_object()'. Like:
$row = odbc_fetch_object($result);