[PHP-users 12940] odbc関数を利用しMSACCESSデータをXMLデータへ

Etsurou Miyazaki php-users@php.gr.jp
Sun, 2 Feb 2003 16:39:36 +0900


This is a multi-part message in MIME format.

------=_NextPart_000_000B_01C2CAD9.AC29CDD0
Content-Type: text/plain;
	charset="iso-2022-jp"
Content-Transfer-Encoding: 7bit

いつもお世話になっております。miyazakiと申します。
私は現在odbc関数を利用しMSACCESSデータをXMLデータとしアパッチに格納するとい
うことをやっております。プログラムの方をHPやマニュアルを参考にさせていただき
一応あるのですが、「odbc_fetch_array」を使用するとエラーが発生してしまうので
「odbc_result」を使用しようと思うのですが、「while($array =
odbc_fetch_array($result, $i)」での処理の方が理解できずになやんでおります。
どなたかodbc_resultをどのように使用するかわかる方いらしましたら、ご教授願え
ませんか。よろしくお願いします。

<ソース抜粋>
//フィールド数
 $fields = odbc_num_fields($result);
 for($i=0;$i<$fields;$i++){
  $field[$i]["name"] = mysql_field_name($result,$i);
  $field[$i]["type"] = mysql_field_type($result,$i);
  }

 //XMLファイルの書きだし
 if(!($fp = fopen("${table}.xml","w"))){
  print ("XMLファイルをオープンできません\n");
  exit;
  }
 fwrite($fp,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet
 type=\"text/xsl\" href=\"mysql.xsl\" ?>\n");

 //DATAの書きだし
 fwrite($fp,"\t<table name=\"zaiko\">\n");
    $id=0;
while($array = odbc_fetch_array($result, $i)){
 $id++;
  fwrite($fp,"\t\t<data no=\"${id}\">\n");
 for($j=0;$j<$fields;$j++){
  $name = $field[$j]["name"];
   $data = $array[$j];
   if($data == ""){
   fwrite($fp,"\t\t\t<${name}/>\n");
  }else{
   fwrite($fp,"\t\t\t<${name}>${data}</${name}>\n");
  }
  }
fwrite($fp,"\t\t</data>\n");
}
 $ret = odbc_close($conn_id);//データベースへの接続を閉じる

fwrite($fp,"\t</table>\n");

 $ret = odbc_close($conn_id);//データベースへの接続を閉じる
 fwrite($fp,"\t</data>\n");



------=_NextPart_000_000B_01C2CAD9.AC29CDD0
Content-Type: text/html;
	charset="iso-2022-jp"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-2022-jp">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B$$$D$b$*@$OC$K$J$C$F$*$j$^$9!#=1B(Bmiyazaki=1B$B$H?=3D$7$^$=
9!#=1B(B</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic"=20
size=3D2>=1B$B;d$O8=3D:_=1B(Bodbc=1B$B4X?t$rMxMQ$7=1B(BMSACCESS=1B$B%G!<%=
?$r=1B(BXML=1B$B%G!<%?$H$7%"%Q%C%A$K3JG<$9$k$H$$$&$3$H$r$d$C$F$*$j$^$9!#%=
W%m%0%i%`$NJ}$r=1B(BHP=1B$B$d%^%K%e%"%k$r;29M$K$5$;$F$$$?$@$-0l1~$"$k$N$G=
$9$,!"!V=1B(Bodbc_fetch_array=1B$B!W$r;HMQ$9$k$H%(%i!<$,H/@8$7$F$7$^$&$N$=
G!V=1B(Bodbc_result=1B$B!W$r;HMQ$7$h$&$H;W$&$N$G$9$,!"!V=1B(Bwhile($array=
=20
=3D odbc_fetch_array($result,=20
$i)=1B$B!W$G$N=3DhM}$NJ}$,M}2r$G$-$:$K$J$d$s$G$*$j$^$9!#$I$J$?$+=1B(Bodbc=
_result=1B$B$r$I$N$h$&$K;HMQ$9$k$+$o$+$kJ}$$$i$7$^$7$?$i!"$465<x4j$($^$;$=
s$+!#$h$m$7$/$*4j$$$7$^$9!#=1B(B</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>=1B$B!c%=3D!<%9H4?h!d=1B(B</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>//=1B$B%U%#!<%k%I?t=1B(B<BR>&nbsp;$fields =3D=20
odbc_num_fields($result);<BR>&nbsp;for($i=3D0;$i&lt;$fields;$i++){<BR>&nb=
sp;&nbsp;$field[$i]["name"]=20
=3D mysql_field_name($result,$i);<BR>&nbsp;&nbsp;$field[$i]["type"] =3D=20
mysql_field_type($result,$i);<BR>&nbsp;&nbsp;}<BR>&nbsp;<BR>=20
//XML=1B$B%U%!%$%k$N=3Dq$-$@$7=1B(B<BR>&nbsp;if(!($fp =3D=20
fopen("${table}.xml","w"))){<BR>&nbsp;&nbsp;print=20
("XML=1B$B%U%!%$%k$r%*!<%W%s$G$-$^$;$s=1B(B\n");<BR>&nbsp;&nbsp;exit;<BR>=
&nbsp;&nbsp;}<BR>&nbsp;fwrite($fp,"&lt;?xml=20
version=3D\"1.0\" encoding=3D\"UTF-8\"?&gt;\n&lt;?xml-stylesheet =
</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;</FONT><FONT face=3D"MS =
UI Gothic"=20
size=3D2>type=3D\"text/xsl\" href=3D\"mysql.xsl\" =
?&gt;\n");</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic"=20
size=3D2>&nbsp;//DATA=1B$B$N=3Dq$-$@$7=1B(B<BR>&nbsp;fwrite($fp,"\t&lt;ta=
ble=20
name=3D\"zaiko\"&gt;\n");<BR>&nbsp;&nbsp;&nbsp; $id=3D0;<BR>while($array =
=3D=20
odbc_fetch_array($result,=20
$i)){<BR>&nbsp;$id++;<BR>&nbsp;&nbsp;fwrite($fp,"\t\t&lt;data=20
no=3D\"${id}\"&gt;\n");<BR>&nbsp;for($j=3D0;$j&lt;$fields;$j++){<BR>&nbsp=
;&nbsp;$name=20
=3D $field[$j]["name"];<BR>&nbsp;&nbsp;&nbsp;$data =3D=20
$array[$j];<BR>&nbsp;&nbsp;&nbsp;if($data =3D=3D=20
""){<BR>&nbsp;&nbsp;&nbsp;fwrite($fp,"\t\t\t&lt;${name}/&gt;\n");<BR>&nbs=
p;&nbsp;}else{<BR>&nbsp;&nbsp;&nbsp;fwrite($fp,"\t\t\t&lt;${name}&gt;${da=
ta}&lt;/${name}&gt;\n");<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>fwrite($fp,=
"\t\t&lt;/data&gt;\n");<BR>}<BR>&nbsp;$ret=20
=3D =
odbc_close($conn_id);//=1B$B%G!<%?%Y!<%9$X$N@\B3$rJD$8$k=1B(B</FONT></DIV=
>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic"=20
size=3D2>fwrite($fp,"\t&lt;/table&gt;\n");</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2>&nbsp;$ret =3D=20
odbc_close($conn_id);//=1B$B%G!<%?%Y!<%9$X$N@\B3$rJD$8$k=1B(B<BR>&nbsp;fw=
rite($fp,"\t&lt;/data&gt;\n");</FONT></DIV>
<DIV><FONT face=3D"MS UI Gothic" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"MS UI Gothic" =
size=3D2>&nbsp;<BR></FONT></DIV></BODY></HTML>

------=_NextPart_000_000B_01C2CAD9.AC29CDD0--