PHP: ora_bind - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ora_close Oracle

Last updated: Sat, 27 Jan 2007

view this page in

# ora_bind

(PHP 3, PHP 4, PHP 5 <= 5.1.0RC1)

ora_bind -- Binds a PHP variable to an Oracle parameter

## Description

bool ora_bind ( resource cursor, string PHP_variable_name, string SQL_parameter_name, int length [, int type] )

This function binds the named PHP variable with a SQL parameter. The SQL parameter must be in the form ":name". With the optional type parameter, you can define whether the SQL parameter is an in/out (0, default), in (1) or out (2) parameter. As of PHP 3.0.1, you can use the constants ORA_BIND_INOUT, ORA_BIND_IN and ORA_BIND_OUT instead of the numbers.

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки. Details about the error can be retrieved using the ora_error() and ora_errorcode() functions.

ora_bind() must be called after ora_parse() and before ora_exec(). Input values can be given by assignment to the bound PHP variables, after calling ora_exec() the bound PHP variables contain the output values if available.

Пример 1. ora_bind() example

`<?php
ora_parse($curs, "declare tmp INTEGER; begin tmp := :in; :out := tmp; :x := 7.77; end;");
ora_bind($curs, "result", ":x", $len, 2);
ora_bind($curs, "input", ":in", 5, 1);
ora_bind($curs, "output", ":out", 5, 2);
$input = 765;
ora_exec($curs);
echo "Result: $result<br />Out: $output<br />In: $input";
?>`

add a note User Contributed Notes
ora_bind
cjbj at hotmail dot com
20-Oct-2003 05:01
`Ahmed's solution is based on the sample given to him in http://forums.oracle.com/forums/thread.jsp?forum=178&thread=206340
Here's a similar example answering the question
"How do I get the return value from a PL/SQL function?"
<?php
/*
Sample using "oracle" driver to get the value of a PL/SQL function.
Before running this script create this function using SQL*Plus:
create or replace function myfunc(myparam IN varchar2) return varchar2 as
begin
return myparam;
end;
Tested with PHP 4.3.3 against Oracle 9.2
*/
$my_db_conn = ora_logon("scott@mydb", "tiger");
$my_cursor = ora_open($my_db_conn);
$sql = "begin :mybindvar := myfunc('abcde'); end;";
ora_parse($my_cursor, $sql, 0);
$r = ora_bind($my_cursor, "mybindvar", ":mybindvar", 5, 1);
// Set the OUT bind variable to anything (?), else get:
// Warning: Can't find variable for parameter
// Notice: Undefined variable: mybindvar
$mybindvar = NULL;
ora_exec($my_cursor);
print 'Return value is: '. $mybindvar;
?>`
ahmed dot adaileh at vaillant dot de
16-Oct-2003 11:38
`It was hard a little bit to understand the example above. Since it did not work properly :(
I managed to get a similar one running, the whole example is as following:
<?php
$connection = ora_logon("user@DBname", "password");
$cursor = ora_open($connection);
ora_commitoff($connection);
$cursor=ora_parse($cursor, "begin user.user_create (:name,:surname,:street,:country,:postal,:city,:tel,:mail,:number); end;");
$name = 'a';
$surname = 'a';
$street = 'a';
$country = 'a';
$postal = 'a';
$city = 'a';
$tel = 'a';
$mail = 'a';
ora_bind($cursor, "name", ":name", 32, 1);
ora_bind($cursor, "surname", ":surname", 32, 1);
ora_bind($cursor, "street", ":street", 32, 1);
ora_bind($cursor, "country", ":country", 32, 1);
ora_bind($cursor, "postal", ":postal", 32, 1);
ora_bind($cursor, "city", ":city", 32, 1);
ora_bind($cursor, "tel", ":tel", 32, 1);
ora_bind($cursor, "mail", ":mail", 32, 1);
ora_bind($cursor, "number", ":number", 32, 2);
// The following step is to charge the output variable with an intial value (Actually still doesn't know why? but it works like this ;-)) )
$okdnr = "a";
ora_exec($cursor);
print "okdnr is $okdnr";
?>
The called stored procedure is as following:
CREATE OR REPLACE procedure customer_create
(
iname in varchar2,
insurname in varchar2,
instreet in varchar2,
incountry varchar2,
inpostal in varchar2,
incity in varchar2,
intel in varchar2,
inemail in varchar2,
okdnr out varchar2)
is
begin
.....
..... SOME CODE ....
.....
okdnr:='something_to_output';
commit;
end customer_create;
/
The most important part of all this is the ora_bind function. Becarefull while writing the syntax regarding the definition wether the variable is an INPUT (1) variable or an OUTPUT variable (2).
Hope this help someone!!`
mukund at ziplip dot com
26-Mar-2001 05:23
`Inputting integers using ORA_BIND.
There is a potential problem in binding oracle integers using php. PHP supports only 32 bit integers where as oracle supports 128. so when you are trying to bind an 128 bit oracle integer, php only interprets the first 32 bits. This results in undesired behaviour. The easiest way around it is not to use bind operations and instead do the whole conversion during the parsing phase. This means you have to parse for each input. A more optimal solution would be to change the oracle inputs to be varchar2 and let oracle deal with the type conversions.`
koos at kzdoos dot xs4all dot nl
28-Feb-2000 09:28
`The Oracle parser doesn't like DOS line endings (cr/lf). Save as Unix file (lf line ending only).`
koos at kzdoos dot xs4all dot nl
07-Jan-2000 11:39
`Passing variables of Oracle type 'DATE' will fail. Just convert them to a string with all the relevant details and convert it back when needed in Oracle, using TO_CHAR and TO_DATE calls in Oracle.`
castle at ruc dot dk
29-Dec-1999 10:50
`ora_bind looks for the bind variables globally. If your are using ora_bind
from within a class you'll have to delcare the bind variables globally and reference them using eg. $GLOBAL["myVar"].`
add a note
ora_close Oracle

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 11:33:19 2007 PST