PHP.mk документација

oci_parse

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.oci-parse.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.oci-parse.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
oci_parse

Референца за `function.oci-parse.php` со подобрена типографија и навигација.

function.oci-parse.php

oci_parse

Класата OCICollection

oci_parsePrepares an Oracle statement for execution

= NULL

oci_parse(resource $connection, string $sql): resource|false

Подготвува Oracle исказ за извршување sql using connection Подготвува oci_bind_by_name(), oci_execute() и враќа идентификатор на исказот, кој може да се користи со

и други функции. oci_free_statement() Идентификаторите на исказите може да се ослободат со null.

Параметри

connection

или со поставување на променливата на oci_connect(), oci_pconnect(), или oci_new_connect().

sql

Идентификатор на Oracle конекција, вратен од

SQL или PL/SQL исказ. SQL искази не треба should да завршуваат со точка и запирка (";"). PL/SQL искази

Вратени вредности

завршуваат со точка и запирка (";"). false при грешка.

Примери

Пример #1 oci_parse() Враќа рачка на исказот при успех, или

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/XE');

// Parse the statement. Note there is no final semi-colon in the SQL statement
$stid = oci_parse($conn, 'SELECT * FROM employees');
oci_execute($stid);

echo
"<table border='1'>\n";
while (
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo
"<tr>\n";
foreach (
$row as $item) {
echo
" <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
}
echo
"</tr>\n";
}
echo
"</table>\n";

?>

Пример #2 oci_parse() пример за SQL искази

<?php

/*
Before running the PHP program, create a stored procedure in
SQL*Plus or SQL Developer:

CREATE OR REPLACE PROCEDURE myproc(p1 IN NUMBER, p2 OUT NUMBER) AS
BEGIN
p2 := p1 * 2;
END;

*/

$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$p1 = 8;

// When parsing PL/SQL programs, there should be a final semi-colon in the string
$stid = oci_parse($conn, 'begin myproc(:p1, :p2); end;');
oci_bind_by_name($stid, ':p1', $p1);
oci_bind_by_name($stid, ':p2', $p2, 40);

oci_execute($stid);

print
"$p2\n"; // prints 16

oci_free_statement($stid);
oci_close($conn);

?>

Белешки

Забелешка:

пример за PL/SQL искази Оваа функција validate sqlне sql . Единствениот начин да се дознае дали

Види Исто така

  • oci_execute() е валиден SQL или PL/SQL исказ е да се изврши.
  • oci_free_statement() - Ослободува сите ресурси поврзани со изјавата или курсорот

Белешки од корисници 5 белешки

interloper на ukr dot net
пред 10 години
If you want using PL/SQL in variable:

<?php
$query = "begin null;  end;";
$stid = oci_parse($conn, "$query");
 ?>

or 

<?php
$stid = oci_parse($conn, "begin null;  end;");
?>
michael dot virnstein на brodos dot de
пред 18 години
A neat way to parse a query only once per script, if the query is done inside a function:

<?php
function querySomething($conn, $id)
{
    static $stmt;

    if (is_null($stmt)) {
        $stmt = oci_parse($conn, 'select * from t where pk = :id');
    }

    oci_bind_by_name($stmt, ':id', $id, -1);

    oci_execute($stmt, OCI_DEFAULT);

    return oci_fetch_array($stmt, OCI_ASSOC);

}

?>

With the static variable, the statment handle isn't closed after the function has terminated. Very nice for functions that are called e.g. in loops. Unfortunately this only works for static sql. If you have dynamic sql, you can do the following:

<?php

function querySomething($conn, $data)
{
    static $stmt = array();
    
    $first = true;
    
    $query = 'select * from t';

    foreach ($data as $key => $value) {
        if ($first) {
            $first = false;
            $query .= ' where ';
        } else {
            $query .= ' and ';
        }
        
        $query .= "$key = :b$key";
    }
    
    $queryhash = md5($query);
   
    if (is_null($stmt[$queryhash])) {
        $stmt[$queryhash] = oci_parse($conn, $query);    
    }

    foreach ($data as $key => $value) {
        // don't use $value, because we bind memory addresses here.
        // this would result in every bind pointing at the same value after foreach
        oci_bind_by_name($stmt[$queryhash], ":b$key", $data[$key], -1);
    }
    
    oci_execute($stmt[$queryhash], OCI_DEFAULT);

    return oci_fetch_array($stmt[$queryhash], OCI_ASSOC);

}

?>
kurt на kovac dot ch
21 години пред
For those that are having trouble with error checking, i have noticed on a lot of sites that people are trying to check the statement handle for error messages with OCIParse. Since the statement handle ($sth) is not created yet, you need to check the database handle ($dbh) for any errors with OCIParse. For example:

instead of:

<?php
$stmt = OCIParse($conn, $query);
if (!$stmt) {
   $oerr = OCIError($stmt);
   echo "Fetch Code 1:".$oerr["message"];
   exit;
} 
?>

use:

<?php
$stmt = OCIParse($conn, $query);
if (!$stmt) {
   $oerr = OCIError($conn);
   echo "Fetch Code 1:".$oerr["message"];
   exit;
} 
?>

Hope this helps someone.
egypt на nmt dot edu
пред 22 години
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
falundir на gmail dot com
пред 15 години
When you want to call stored function (and want to read its result) which executes DML queries (insert, update, delete) inside its body you can't use "select your_stored_function(:param1, :param2) from dual" because you will receive "ORA-14551: cannot perform a DML operation inside a query" error.

In order to call such function and get its result you need to wrap it into nested procedure with OUT parameter like this:

DECLARE
  PROCEDURE caller(return_value OUT NUMBER) AS
  BEGIN
    return_value := your_stored_function(:param1, :param2);
  END;
BEGIN
  caller(:return_value);
END;

and bind to :return_value variable to get the result of function.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.