note 20005 added to function.ocierror
| From: | vi at sh dot nu | Date: | Tue, 19 Mar 2002 00:05:59 +0000 |
| Subject: | note 20005 added to function.ocierror | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27935@lists.php.net to get a copy of this message | ||
// ATTENTION NOTES MODERATOR, THERE'S A COMMENT BELOW WITH SOME INSTRUCTIONS...PLEASE READ IT
AND FOLLOW THE INSTRUCTIONS, IF IT'S NOT TOO MUCH TO ASK...THANKS (DON'T FORGET TO REMOVE
THESE 'NOTES MODERATOR' COMMENTS :)
Hi,
I thought I'd include an example on how to use the above patch, which has been recently
commited to CVS.
<?
$conn = OCILogon ("bla", "bla", "bla");
// I'm very anal about formatting
$sql = "
select
t.foo,
t.bar
from
table t
where
t.id = 1";
$stmt = OCIParse ($conn, $sql);
// Suppress the warning generated here using @
@OCIExecute ($stmt, OCI_DEFAULT);
$error = OCIError ($stmt);
// ATTENTION NOTES MODERATOR!! CAN YOU PLEASE CLEAN UP THE CODE BELOW? IT LOOKS LIKE ASS WHEN I
PREVIEW AND I CAN'T GET IT TO LOOK ANY BETTER THAN THIS...THANKS
if ($error["code"]) {
$sqltext = substr ($error["sqltext"], 0, $error["offset"]) .
'<span style="color:#FF0000;
font-weight:bold"><ERROR></span>' . substr
($error["sqltext"], $error["offset"]);
die ("<pre>" . $sqltext . "\n\n</pre>\n"
. $error["code"] . " : " . $error["message"]);
}
?>
Assuming the column "bar" doesn't exist in table "t", the above code will
print:
// ATTENTION NOTES MODERATOR!! CAN YOU ALSO PLEASE MAKE THIS ONE LINE HERE NOT WRAP? THANKS
select
t.foo,
t.<span style="color:#FF0000;
font-weight:bold"><ERROR></span>bar
from
table t
where
t.id = 1
904 : ORA-00904: invalid column name
Of course, the best way to do this is by using a class to wrap all the OCI calls, which I'm
sure you already do. :)
Daniel Ceregatti
--
http://www.php.net/manual/en/function.ocierror.php
http://master.php.net/manage/user-notes.php?action=edit+20005
http://master.php.net/manage/user-notes.php?action=delete+20005
http://master.php.net/manage/user-notes.php?action=reject+20005