【问题标题】:How to get DBMS_ADDM report output through PHP如何通过 PHP 获取 DBMS_ADDM 报告输出
【发布时间】:2017-03-24 22:02:29
【问题描述】:

我正在尝试获取 Oracle 数据库的 ADDM 报告。输出以 .txt 形式的数组形式。我需要以表格行格式显示它。但是我没有得到想要的输出。

  $today = date("His");
  $taskname =$username.$today;
  $taskquery = "BEGIN DBMS_ADDM.ANALYZE_INST(:tname,     :bsnap,:esnap,:instnum);END;";
  $stid = oci_parse($conn,$taskquery);
  oci_bind_by_name($stid, ":tname", $taskname);
  oci_bind_by_name($stid, ":bsnap", $bsnap);
  oci_bind_by_name($stid, ":esnap", $esnap);
  oci_bind_by_name($stid, ":instnum", $inst);
  oci_execute($stid);
  $mainquery = "SELECT DBMS_ADDM.GET_REPORT(:tname) from dual";
  $stid = oci_parse($conn,$mainquery);
    oci_bind_by_name($stid, ":tname", $taskname);
    oci_execute($stid);
    echo "<table border='1'>\n";
   while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
       echo "<tr>\n";
      foreach ($row as $item) {
           echo "    <td>" . $item . "</td>\n";
       }
  echo "</tr>\n";
  }
  echo "</table>\n";

现在这会返回一个错误:OCI-Lob 类的对象无法转换为字符串

所以我在 $stid 上执行 oci_fetch_all 后尝试了 var_dump,得到了这个:

array (size=1)
  'DBMS_ADDM.GET_REPORT(:TNAME)' => 
    array (size=1)
      0 => string '          ADDM Report for Task...and rest of the report shows here'

我如何回显显示报告的那个字符串,因为它以正确的格式显示它,我会在 shell 上得到它。这是为了前端 UI 目的。

【问题讨论】:

    标签: php arrays database oracle dbms-output


    【解决方案1】:

    我得到了这个问题的答案。 所以事实证明,PHP 的 shell_exec 函数在对 Linux 格式的 txt 文件执行简单的 cat 命令方面做得非常出色。所以我只是简单地将显示字符串的变量输出到一个txt文件中,然后简单地shell_exec('cat filename')

    这么简单!!!

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 1970-01-01
      • 2018-03-04
      • 2022-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多