note 37250 added to function.ociexecute
| From: | gord_c at ntlworld dot com | Date: | Fri, 07 Nov 2003 15:37:32 +0000 |
| Subject: | note 37250 added to function.ociexecute | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60097@lists.php.net to get a copy of this message | ||
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>";
----
Manual Page -- http://www.php.net/manual/en/function.ociexecute.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37250
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37250&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37250&report=yes
Search -- http://master.php.net/manage/user-notes.php