note 37250 deleted from function.ociexecute by didou
| From: | didou@php.net | Date: | Fri, 07 Nov 2003 15:42:25 +0000 |
| Subject: | note 37250 deleted from function.ociexecute by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-60098@lists.php.net to get a copy of this message | ||
Note Submitter: gord_c@ntlworld.com
----
I couldn't get the error capture example to work for me, maybe because my php version is quite
old. Here's a workaround that catches the php screen output for any errors:
ob_start(); //capture buffer output to catch error message
$testQuery = stripslashes($query); //remove any encoding from passed query
//enclose the query to test within plsql
$startplsql = "declare query_count number;begin select count(*) into query_count
from(\n";
$endplsql = "\n);end;";
$plsql = $startplsql.$testQuery.$endplsql;
$stmt = OCIParse($conn, "$plsql");
$tested = (OCIExecute($stmt, OCI_DEFAULT)); //boolean for execute success
$error = ob_get_contents(); //pass any error output captured to $error variable
ob_end_clean(); //stop capturing buffer output
$querylines = explode("\n",$testQuery); //split the lines of the original query to
match line number
$theLine = -1; //will stay at -1 unless an error message exists
print "<TABLE ALIGN=CENTER>";
if (!$tested)
{
$errorbits = explode(":",$error); //break up error into seperate elements
//remove text from the portion with error coordinates
$errorbits[3] = str_replace(" line ","",$errorbits[3]);
$errorbits[3] = str_replace(" column ","",$errorbits[3]);
$coords = explode(",",$errorbits[3]); //split coords up
$theLine = $coords[0]-2; //offset returned value to match the elements of $querylines array
$theCol = $coords[1]-1; //offset x by 1 as php starts from 0 for string position
print "<TR><TH>The highlighted section of your query failed with the
following error<BR>";
print "$errorbits[2]: $errorbits[5]</TH></TR><TR><TD
ALIGN=CENTER>";
} else {
print "<TR><TH>The query tested
successfully</TH></TR><TR><TD ALIGN=CENTER>";
}
for ($lp=0;$lp<sizeof($querylines);$lp++)
{
if ($lp==$theLine)
{
$getWord = explode ("
",substr($querylines[$lp],$theCol,strlen($querylines[$lp])));
$endWord = $theCol+strlen($getWord)-1;
print "<BR>".substr($querylines[$lp],0,$theCol);
print "<FONT
COLOR=red>".$getWord[0]."</FONT>";
array_shift($getWord);
$lastWords = implode(" ",$getWord);
print " $lastWords";
} else {
print "<BR>$querylines[$lp]";
}
}
print "</TD></TR></TABLE>";