Just to write it down. I was trying to do a simple SELECT on a Caché (http://www.intersystems.com/cache/) table through an Oracle dblink, but always received the error "ORA-01002: fetch out of sequence". The solution was using OCI_NO_AUTO_COMMIT on the oci_execute function.
oci_execute
(PHP 5, PECL oci8 >= 1.1.0)
oci_execute — Executes a statement
Описание
Executes a previously parsed statement .
Параметри
- statement
-
A valid OCI statement identifier.
- mode
-
Allows you to specify the execution mode (default is OCI_COMMIT_ON_SUCCESS).
If you don't want statements to be committed automatically, you should specify OCI_DEFAULT as your mode .
When using OCI_DEFAULT mode, you're creating a transaction. Transactions are automatically rolled back when you close the connection, or when the script ends, whichever is soonest. You need to explicitly call oci_commit() to commit the transaction, or oci_rollback() to abort it.
Връщани стойности
Връща TRUE при успех или FALSE при неуспех.
Бележки
Забележка: In PHP versions before 5.0.0 you must use ociexecute() instead. This name still can be used, it was left as alias of oci_execute() for downwards compatability. This, however, is deprecated and not recommended.
Notice (PHP 5.2.12-pl0-gentoo):
You can parse empty query, you can execute empty query (returns true), but you cannot fetch data from empty query. So, if you provide query as variable, make sure it isn't empty.
<?php
$q = oci_parse($c, "");
if($q != false){
// parsing empty query != false
if(oci_execute($q){
// executing empty query != false
if(oci_fetch_all($q, $data, 0, -1, OCI_FETCHSTATEMENT_BY_ROW) == false){
// but fetching executed empty query results in error (ORA-24338: statement handle not executed)
$e = oci_error($q);
echo $e['message'];
}
}
else{
$e = oci_error($q);
echo $e['message'];
}
}
else{
$e = oci_error($link);
echo $e['message'];
}
?>
