Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

not a valid oci8 statement resource

763719Mar 30 2010 — edited Apr 12 2010
I've been grappling this problem sometime, google doesn't help because all the results I get are pages with the same error.

Warning: oci_fetch(): 3 is not a valid oci8 statement resource in /home/dsk10/ugrad/bejhan/web_docs/facttable.php on line 21

Line 21 is: while(oci_fetch($SQL)) {

My loop functions correctly and fetches the results properly though. Here is my connect and creation of the statement:

$c = oci_connect("bejhan", "******");
$SQL = oci_parse($c, "SELECT TIMETRANSACTIONID, TO_CHAR(TDATETIME, 'YYYY-MM-DD HH24:MI:SS') AS PHPDATE, DURATION, TIMECODEDEFID, TEAM, MATERIALTYPE FROM c391.TimeTransactionData78 WHERE ROWNUM < 10 ORDER BY TDATETIME");
oci_execute($SQL);

When I run this query in SQLPlus I don't receive any errors.

What is causing this warning?

Comments

Add some error checking after each OCI call.

See the section "How do I check my SQL statements are working?" in http://wiki.oracle.com/page/PHP+Oracle+FAQ
763719
Okay changed the code to:

$c = oci_connect("bejhan", "******");
$SQL = oci_parse($c, "SELECT TIMETRANSACTIONID, TO_CHAR(TDATETIME, 'YYYY-MM-DD HH24:MI:SS') AS PHPDATE, DURATION, TIMECODEDEFID, TEAM, MATERIALTYPE FROM c391.TimeTransactionData78 WHERE ROWNUM < 10 ORDER BY TDATETIME");

$error = oci_error();
if($error)
echo "SQL ERROR: (" . $error['message'] . ")";
else
echo "NO ERROR";

oci_execute($SQL);

$error = oci_error();
if($error)
echo "SQL ERROR: (" . $error['message'] . ")";
else
echo "NO ERROR";

//Fix problem with fetch statement
while(oci_fetch($SQL)) {

$error = oci_error();
if($error)
echo "SQL ERROR: (" . $error['message'] . ")";
else
echo "NO ERROR";

However, I just get NO ERROR for all of these.
Your oci_error() calls are incorrect. The manual shows the correct syntax.
763719
My mistake, I believe my syntax is correct now, still no error messages:

$c = oci_connect("bejhan", "******");
$SQL = oci_parse($c, "SELECT TIMETRANSACTIONID, TO_CHAR(TDATETIME, 'YYYY-MM-DD HH24:MI:SS') AS PHPDATE, DURATION, TIMECODEDEFID, TEAM, MATERIALTYPE FROM c391.TimeTransactionData78 WHERE ROWNUM < 10 ORDER BY TDATETIME");

if(!$c) {
$error = oci_error($c);
echo "SQL ERROR: (" . $error['message'] . ")";
} else
echo "NO ERROR";

oci_execute($SQL);

if(!$SQL) {
$error = oci_error($c);
echo "SQL ERROR: (" . $error['message'] . ")";
} else
echo "NO ERROR";

Shouldn't the $SQL be false if the statement is invalid?
Try this:
$c = oci_connect("bejhan", "******");
if (!$c) {
    $error = oci_error();
    echo "Connection ERROR: (" . $error['message'] . ")";
} else
    echo "NO ERROR";

$SQL = oci_parse($c, "SELECT TIMETRANSACTIONID, TO_CHAR(TDATETIME, 'YYYY-MM-DD HH24:MI:SS') AS PHPDATE, DURATION, TIMECODEDEFID, TEAM, MATERIALTYPE FROM c391.TimeTransactionData78 WHERE ROWNUM < 10 ORDER BY TDATETIME");
if (!$SQL) {
    $error = oci_error($c);
    echo "Parse ERROR: (" . $error['message'] . ")";
} else
    echo "NO ERROR";

$r = oci_execute($SQL);
if (!$r) {
    $error = oci_error($SQL);
    echo "Execution ERROR: (" . $error['message'] . ")";
} else
    echo "NO ERROR";
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 10 2010
Added on Mar 30 2010
5 comments
9,062 views