EDIT// Problem solved - I have re-written my code into a PL/SQL package and function, so I can now simply call this using a standard select statement. I will leave my original query below and a couple of links I found useful for anyone in a similar position.
Links
- http://www.plsql-tutorial.com/plsql-functions.htm
- Creating and calling PL/SQL functions
- http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.apdv.plsql.doc%2Fdoc%2Fr0054067.html
Original query
I have been trying to a long long time to get my PHP code to successfully process my PL/SQL dbms_output. I cannot seem to get it to work. The rest of the code works, and in SQL developer I get the correct outputs. The error reporting works too as if I leave anything out of the code I get the errors reported (e.g. not caching the network). It is just not giving me my final output. Here is the dbms_output sections of my code in PHP.
// Fetch and display any dbms_output
function DisplayDbmsOutput($con)
{
$r = GetDbmsOutput($con);
if (!$r)
print "<p>Error getting dbms_output</p>\n";
else
foreach ($r as $line)
echo $line."<br>\n";
}
// Returns an array of dbms_output lines, or false.
function GetDbmsOutput($con)
{
$res = false;
$stid = doParse($con, "BEGIN DBMS_OUTPUT.GET_LINE(:LN, :ST); END;");
if ($stid) {
if (doBind($stid, ":LN", $ln, 255) &&
doBind($stid, ":ST", $st, "")) {
$res = array();
while ($succ = doExecute($stid)) {
if ($st)
break;
$res[] = $ln;
}
if (!$succ)
$res = false;
}
@OCIFreeStatement($stid);
}
return ($res);
}
// Cache Network
CacheNetwork($con, true);
// turn serveroutput on
SetServerOutput($con, true);
// Create dbms_output
$s = doParse($con, "
DECLARE
cost NUMBER;
path_id NUMBER;
res_numeric NUMBER;
res_array SDO_NUMBER_ARRAY;
Nav_Info Test_Turns.Navigation_Info%TYPE;
Walk_Dist chadwick_link$.cost%TYPE;
Starting_Node_ID chadwick_link$.Start_Node_ID%TYPE;
Ending_Node_ID chadwick_link$.End_Node_ID%TYPE;
start_node_id Number;
goal_node_id Number;
goal_node varchar(20);
txtArray dbms_output.chararr;
numLines integer := 4;
BEGIN
start_node_id := 34;
goal_node_id := 19;
goal_node := '%' || ' ' || (to_Char(goal_node_id)) || ',' || '%';
path_id := sdo_net_mem.network_manager.shortest_path('CHADWICK', start_node_id, goal_node_id);
cost := SDO_NET_MEM.PATH.GET_COST('CHADWICK', path_id);
res_array := SDO_NET_MEM.PATH.GET_LINK_IDS('CHADWICK', path_id);
FOR indx IN res_array.FIRST..res_array.LAST
LOOP
Select Start_Node_ID INTO Starting_Node_ID from chadwick_link$ where Link_ID = res_array(indx);
Select End_Node_ID INTO Ending_Node_ID from chadwick_link$ where Link_ID = res_array(indx);
Select Navigation_Info INTO Nav_Info from Test_Turns_Two where Starting_Node = Starting_Node_ID and Finishing_Node = Ending_Node_ID and possible_finish_nodes Like goal_node;
select cost INTO Walk_Dist from chadwick_link$ where link_id = res_array(indx);
DBMS_OUTPUT.PUT(Nav_Info || ' ' || Walk_Dist || ' meters');
END LOOP;
DBMS_OUTPUT.PUT('You have arrived at your destination');
DBMS_OUTPUT.PUT(' ');
END;
");
if ($s)
doExecute($s);
// Display the output
DisplayDbmsOutput($con);
Any suggestions would be wonderful!
DisplayDbmsOutputever get called, and does it ever step into the code which should be callingDBMS_OUTPUT.GET_LINE?doParseordoExecuteare not returning a valid values, or one of thedoBindcalls is failing. Are these routines something you wrote? If so, perhaps you could add some code to print something which tells more about what's going wrong.