title: Cannot get dbms_output to work in PHP (connecting to Oracle database)
body: <p><strong>EDIT// Problem solved</strong> - 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.</p>
  
  <p><em>Links</em></p>
  
  <ul>
  <li><a href="http://www.plsql-tutorial.com/plsql-functions.htm" rel="nofollow noreferrer">http://www.plsql-tutorial.com/plsql-functions.htm</a></li>
  <li><a href="https://stackoverflow.com/questions/11291693/creating-and-calling-pl-sql-functions">Creating and calling PL/SQL functions</a></li>
  <li><a href="http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.apdv.plsql.doc%2Fdoc%2Fr0054067.html" rel="nofollow noreferrer">http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.apdv.plsql.doc%2Fdoc%2Fr0054067.html</a></li>
  </ul>
  
  <p><em>Original query</em></p>
  
  <p>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.</p>
  
  <pre><code>// Fetch and display any dbms_output
  function DisplayDbmsOutput($con)
  {
    $r = GetDbmsOutput($con);
  
   if (!$r)
       print "&lt;p&gt;Error getting dbms_output&lt;/p&gt;\n";
   else
      foreach ($r as $line)
        echo $line."&lt;br&gt;\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) &amp;&amp;
          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);
  </code></pre>
  
  <p>Any suggestions would be wonderful!</p>