誰かが私を助けてくれたらとても嬉しいです:)
Oracle DBからクエリを読み取り、結果をXMLとして表示するphpWebサービスを作成しようとしています。私は解決策を探すのに何日も費やしましたが、残念ながらそれはうまくいきませんでした
以下は私が試したいくつかのクエリです:
<?php
$db ="(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1530))
)
(CONNECT_DATA=(SID=DEV))
)";
$c = oci_connect("uname", "pass", $db);
$q = "select dbms_xmlgen.getxml(
'select user_name
from fnd_user
where user_name = 007144') xml
from dual";
$s = oci_parse($c, $q);
oci_execute($s);
$r = oci_fetch_array($s, OCI_ASSOC);
$mylob = $r['XML']->load(); // Treat column data as a LOB descriptor
echo "<pre>";
echo htmlentities($mylob);
echo "</pre>";
?>
2番目のコード:
<?php
//File: DOM.php
$db="(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)
(HOST=xxx)(PORT=1530)
) )
(CONNECT_DATA=(SID=DEV))
)";
$conn = OCILogon("uname","pass",$db);
if ($conn) {
//echo "Successfully connected to Oracle.";
} else {
$err = oci_error();
echo "Oracle Connect Error " . $err['text'];
}
$query = "SELECT user_name from fnd_user where user_name = '007144'";
$stmt = oci_parse($conn,$query);
if (!oci_execute($stmt, OCI_DEFAULT)) {
$err = oci_error($stmt);
trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
}
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement('EMPLOYEES', 'Root');
$dom->appendChild($root);//$root = $dom->appendChild($root);
while ($row = oci_fetch_array($stmt, OCI_RETURN_NULLS))
{
$emp = $dom->createElement('EMPLOYEE', 'emp');
$emp = $root->appendChild($emp);
$emp->setAttribute('id', $row['user_name']);
/*
$emp = $dom->createElement('EMPLOYEE', '');
$emp = $root->appendChild($emp);
$emp->setAttribute('id', $row['user_name']);
$ename = $dom->createElement('ENAME', $row['user_name']);
$ename = $emp->appendChild($ename);
$salary = $dom->createElement('SALARY', $row['user_name']);
$salary = $emp->appendChild($salary);
*/
}
echo $dom->saveXML();
//$dom->save("employees.xml");
oci_close($conn);
?>
上記のコードは、下の図のようにデータなしのXMLを提供します。 http://i48.tinypic.com/2lnv5eo.jpg
3番目のコード
<?php
//File: XMLFromSQL.php
$user = 'uname';
$pswd = 'pass';
$db ='(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1530))
)
(CONNECT_DATA=(SID=DEV))
)';
$sql = "SELECT user_name as RESULT FROM fnd_user
WHERE user_name=:deptno";
$deptno = 007144;
//Connect to the database and obtain info on a given department in XML format
$conn = oci_connect($user, $pswd, $db);
$query = oci_parse($conn, $sql);
oci_bind_by_name($query, ":deptno", $deptno, 2);
oci_execute($query);
oci_fetch($query);
$strXMLData = oci_result($query, 'RESULT');
//Create a new DOM document and load XML into its internal XML tree
$doc = new DOMDocument("1.0", "UTF-8");
$doc->loadXML($strXMLData);
//For simplicity, just print out the XML document
print $doc->saveXML();
?>
別の方法があれば私を助けてください、さもないと私は夢中になります:(