(PHP 5.3.2 (aka PECL OCI8 >= 1.4) adds a new constant that can be used with oci_execute(). It is an alias of OCI_DEFAULT.
OCI_NO_AUTO_COMMIT (integer)
Statement execution mode. Statement is not committed automatically
when using this mode. For readability, use OCI_NO_AUTO_COMMIT
instead of the obsolete OCI_DEFAULT constant.
oci_execute
(PHP 5, PECL oci8 >= 1.1.0)
oci_execute — 文を実行する
説明
bool oci_execute
( resource $statement
[, int $mode = OCI_COMMIT_ON_SUCCESS
] )
事前にパースされた statement を実行します。
パラメータ
- statement
-
有効な OCI ステートメント ID
- mode
-
実行モードを指定することを可能にする (デフォルトは OCI_COMMIT_ON_SUCCESS) 。
自動的にコミットされたくない場合は、 mode に OCI_DEFAULT に指定する。
OCI_DEFAULT モードを使用する場合、 トランザクションを生成する。 トランザクションは接続を閉じたとき、 もしくはスクリプトの終了時のいずれの場合でも すぐに自動的にロールバックされる。 トランザクションをコミットするには oci_commit() を、 トランザクションを破棄する場合は oci_rollback() をそれぞれ明示的にコールする必要がある。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
注意
注意: PHP バージョン 5.0.0 以前では、代わりに ociexecute() を使用しなければなりません。 まだこの名前を使用することができ、下位互換性のため oci_execute() への別名として残されていますが、 推奨されません。
oci_execute
sixd at php dot net
07-Oct-2009 01:09
07-Oct-2009 01:09
pcythe at gmail dot com
29-Oct-2008 01:38
29-Oct-2008 01:38
In addition to executing the previously parsed statement, oci_execute also validates the SQL query being passed to oci_parse.
If an error is detected oci_execute gives a "ORA-00900: invalid SQL statement" warning.
23-Feb-2006 05:56
Mode OCI_DESCRIBE_ONLY is supported as of the fix to http://bugs.php.net/bug.php?id=36403
Flo at yahoo dot com
17-Jun-2004 11:40
17-Jun-2004 11:40
Termin.php
<?php
session_start();
if(!session_is_registered("db"))
{
$_SESSION["user"] = $_POST["user"];
$_SESSION["pass"] = $_POST["pass"];
$_SESSION["db"] = $_POST["db"];
}
$logdata[0] = $_SESSION["user"];
$logdata[1] = $_SESSION["pass"];
$logdata[2] = $_SESSION["db"];
$conn = OCILogon($logdata[0],$logdata[1],$logdata[2]);
$sql = "Select T.TEID, TEDATUM, TEUhrzeit, TEORT, TEBeschreibung, KLID as GRID, KLBezeichnung as Bezeichnung From TTermine T, TGruppetermin G, TKLASSE K Where T.TEID=G.TEID AND GRID=K.KLID";
$stmt = OCIParse($conn, $sql);
OCIExecute($stmt);
$rows = OCIFetchstatement($stmt,$results);
$keys = array_keys($results);
$table = "<table>\n <TR>\n";
foreach($keys as $key)
{
$table .= " <TH>$key</TH>\n";
}
$table .= " </TR>\n";
for($i=0;$i<$rows;$i++)
{
$table .= " <TR>";
foreach($results as $spalte)
{
$data = $spalte[$i];
$table .= " <TD>$data</TD>";
}
$table .=" </TR>";
}
$sql = "Select T.TEID, TEDATUM, TEUhrzeit, TEORT, TEBeschreibung, BIID as GRID, BIBezeichnung as Bezeichnung From TTermine T, TGruppetermin G, TBILDUNGSGANG B Where T.TEID=G.TEID AND GRID=B.BIID";
$stmt = OCIParse($conn, $sql);
OCIExecute($stmt);
$rows = OCIFetchstatement($stmt,$results);
for($i=0;$i<$rows;$i++)
{
$table .= " <TR>";
foreach($results as $spalte)
{
$data = $spalte[$i];
$table .= " <TD>$data</TD>";
}
$table .=" </TR>";
}
$sql = "Select T.TEID, TEDATUM, TEUhrzeit, TEORT, TEBeschreibung, BEID as GRID, BEBezeichnung as Bezeichnung From TTermine T, TGruppetermin G, TBERUFSFELD B Where T.TEID=G.TEID AND GRID=B.BEID";
$stmt = OCIParse($conn, $sql);
OCIExecute($stmt);
$rows = OCIFetchstatement($stmt,$results);
for($i=0;$i<$rows;$i++)
{
$table .= " <TR>";
foreach($results as $spalte)
{
$data = $spalte[$i];
$table .= " <TD>$data</TD>";
}
$table .=" </TR>";
}
$table .="</TABLE>";
/***************************/
//echo "$table";
/***************************/
$sql = "Select BIID From TBILDUNGSGANG";
$stmt = OCIParse($conn, $sql);
OCIExecute($stmt);
$rows = OCIFetchstatement($stmt,$results);
$biid = $results[BIID];
$select = "<SELECT NAME=\"biid\">\n";
foreach($biid as $data)
{
$select .= " <OPTION VALUE=\"$data\">$data</OPTION>\n";
}
$select .= "</select>";
//echo $select;
echo <<< HTML
<HTML>
<HEAD>
<TITLE>TERMIN.PHP</TITLE>
</HEAD>
<BODY>
<H1>Willkommen bei Termin.PHP</H1>
Hier sind alle termine<br>
$table
<p>Sie können sich Termine von Klassen bestimmter Bildungsgaänge ansehen. Einfach auswählen.</p>
<form action="$PHP_SELF" method="post">
$select<br>
<input type="submit">
</form>
HTML;
$biid = $_POST["biid"];
if(isset($biid))
{
$sql = "Select klid, KlBezeichnung, T.TEID, TEDATUM, TEUHRZEIT, TEORT, TEBeschreibung from Tklasse K, TGruppetermin G, TTermine T where Grid=BIID AND T.TEID=G.TEID AND BIID='$biid'";
$stmt = OCIParse($conn, $sql);
OCIExecute($stmt);
$rows = OCIFetchstatement($stmt,$results);
$keys = array_keys($results);
$table = "<table>\n <TR>\n";
foreach($keys as $key)
{
$table .= " <TH>$key</TH>\n";
}
$table .= " </TR>\n";
for($i=0;$i<$rows;$i++)
{
$table .= " <TR>";
foreach($results as $spalte)
{
$data = $spalte[$i];
$table .= " <TD>$data</TD>";
}
$table .=" </TR>";
}
if($rows>0)
{
echo $table;
}
}
echo "</BODY>\n</HTML>";
?>
jicurito at hotmail dot com
10-Dec-2003 12:41
10-Dec-2003 12:41
regarding egypt note on double quotes, the reason for that behaviour is that Oracle treats things with double quotes as identifiers on a given statement... using single quotes won't provoque mistakes...
egypt at nmt dot edu
15-Oct-2003 02:31
15-Oct-2003 02:31
Whereas MySQL doesn't care what kind of quotes are around a LIKE clause, ociexecute gives the error:
ociexecute(): OCIStmtExecute: ORA-00904: "NM": invalid identifier
for the following.
<?php
$sql = "SELECT * FROM addresses "
. "WHERE state LIKE \"NM\""; // error!
$stmt = ociparse($conn, $sql);
ociexecute($stmt);
?>
it's fine if you just use single quotes:
. "WHERE state LIKE 'NM'";
but i think it's interesting that ociparse doesn't say anything
kobbe at lausitz dot net
22-Jan-2003 09:43
22-Jan-2003 09:43
If you use OCI_DEFAULT and OCIRollback, don't forget that a simple SELECT-statement works with an commit that has also an effect on all previously statements.
Los Olvidados
16-Jan-2003 09:46
16-Jan-2003 09:46
Every time you call ociexecute(), the setting for autocommit may change. If you don't want autocommit on, be sure to use OCI_DEFAULT for every call to ociexecute.
alexander dot zimmer at gmx dot at
19-Sep-2002 05:18
19-Sep-2002 05:18
Addition to the posting of cthrall@rocketmail.com (from 06-Sep-2000):
It's true, you can't call OCIBindByName in a loop and bind to an associative array like this:
foreach ($array as $key => $val)
{
OCIBindByName($state, $key, $val, -1);
}
BUT: You can do it this way:
foreach ($array as $key => $val)
{
OCIBindByName($state, $key, $array[$key], -1);
}
Background: the command OCIBindByName BINDS a PHP variable to a parameter, not just its current value. Thus, it is up to you to make sure that the variable has the correct value at the very time when OCIExecute is called, not just when OCIBindByName was called! The PHP variable gets evaluated at the point of OCIExecute and not earlier.
This is somewhat more legible than cthrall's solution (but it surely works, too).
jgrosland at buildscape dot com
07-Sep-1999 05:57
07-Sep-1999 05:57
There seems to be some interesting behavior when using OCI_DEFAULT as the second parameter to ociexecute... once the autocommit behavior is turned off for a connection, it remains off for the life of that connection.
This tends to be a problem when using OCIPLogon, as a SQL statement may remain outstanding over the life of many webpages.
This is most problematic when you're doing an update or insert, and a table remains locked while that connection is waiting for a commit/rollback. Be sure to explicitly commit or rollback if you use OCI_DEFAULT at any point.
robra at lazarus dot stack dot nl
16-Aug-1999 11:31
16-Aug-1999 11:31
To catch what an error was about, I use a piece of PL/SQl instead of just a SELECT. For instance:
<?php
$query="BEGIN
SELECT user_id INTO :v_user_id FROM rw_users
WHERE gebruikersnaam = LOWER(:p_alias);
:ERROR := 0;
EXCEPTION
when others then
:ERROR := 1;
:SQLCODE := SQLCODE;
:SQLERRM := SUBSTR(SQLERRM,0,300);
END; ";
$stmt = OCIParse($conn, $query);
/* Output parameters */
OCIBindByName($stmt,":ERROR",&$insert_error,32);
OCIBindByName($stmt,":SQLCODE",&$SQLCODE,32);
OCIBindByName($stmt,":SQLERRM",&$SQLERRM,300);
OCIBindByName($stmt,":v_user_id",&$v_user_id,32);
/* Input parameters */
OCIBindByName($stmt,":p_alias", &$p_alias, strlen($p_alias)+2);
$exec_result = OCIExecute($stmt,OCI_DEFAULT);
?>
Now if the select causes an exception, it is caught and the error message is stored.
