Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Oracle Functions [deprecated] : ora_bind

ora_bind

Binds a PHP variable to an Oracle parameter (PHP 4, PHP 5 <= 5.0.5)
bool ora_bind ( resource cursor, string phpvar, string sqlparam, int length [, int type] )

Example 1679. 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";
?>

Code Examples / Notes » ora_bind

koos

The Oracle parser doesn't like DOS line endings (cr/lf). Save as Unix file (lf line ending only).

castle

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"].


ahmed dot adaileh

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

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.


cjbj

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;
?>


Change Language


Follow Navioo On Twitter
ora_bind
ora_close
ora_columnname
ora_columnsize
ora_columntype
ora_commit
ora_commitoff
ora_commiton
ora_do
ora_error
ora_errorcode
ora_exec
ora_fetch_into
ora_fetch
ora_getcolumn
ora_logoff
ora_logon
ora_numcols
ora_numrows
ora_open
ora_parse
ora_plogon
ora_rollback
eXTReMe Tracker