dinhchung82
asked on
Get value by calling oracle function in PHP!
I create php page to bind the value in oracle function named balance1
2 codes are below .
My question is How to i get the value that is returned by oracle and display it .
2 codes are below .
My question is How to i get the value that is returned by oracle and display it .
PHP code :
<?php
$conn = oci_connect('abc', 'test', 'test');
$sql = ' begin balance1(:cardnumber); end; ';
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':cardnumber',$cardnumber,32);
$cardnumber = '5xxxxxxxxxxxxx';
oci_execute($stmt);
?>
oracle function :
create or replace function balance1(v_cardnumber in varchar2 )
return varchar2
is
....
return
end balance1;
ASKER
$cardnumber = '5xxxxxxxxxxxxx';
This is the value that i pass to the ":cardnumber "
I cannot remove it
Thanks!
This is the value that i pass to the ":cardnumber "
I cannot remove it
Thanks!
ASKER
I try to change Function balance 1 to Procedure balance
Definition for balance :
create or replace procedure balance(v_cardnumber in varchar2,trnamntstr out varchar2 ) is
.....
end balance
and the Php i change is :
<?php
$conn = oci_connect('aaa', 'bbb', 'test') or die('Cannot connect') ;
$sql = 'BEGIN balance(:cardnumber,:trnam ntstr); END;';
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':c ardnumber' ,$cardnumb er,32);
oci_bind_by_name($stmt,':t rnamntstr' ,$trnamnts tr,32);
$cardnumber = '5212345678991111';
oci_execute($stmt);
print "$trnamntstr\n";
?>
But the output is nothing ?
Would anybody have idea ?
Definition for balance :
create or replace procedure balance(v_cardnumber in varchar2,trnamntstr out varchar2 ) is
.....
end balance
and the Php i change is :
<?php
$conn = oci_connect('aaa', 'bbb', 'test') or die('Cannot connect') ;
$sql = 'BEGIN balance(:cardnumber,:trnam
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':c
oci_bind_by_name($stmt,':t
$cardnumber = '5212345678991111';
oci_execute($stmt);
print "$trnamntstr\n";
?>
But the output is nothing ?
Would anybody have idea ?
CHECK WHETHER THE PROCEDURE IS GIVING PROPER OUTPUT by executing it in sqlplus;
set serveroutput on
decare
v_output varchar2(100);
begin
balance( '5212345678991111',v_outpu t );
dbms_output.put_line(v_out put);
end;
set serveroutput on
decare
v_output varchar2(100);
begin
balance( '5212345678991111',v_outpu
dbms_output.put_line(v_out
end;
ASKER
yes, the balance is okie and return the result .
But when call it from PHP page , i cannot receive the expected result.
Thanks
But when call it from PHP page , i cannot receive the expected result.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I try this but nothing returns !!!!
<?php
$conn = oci_connect('abc', 'abc', 'test') or die('Cannot connect') ;
$sql = 'BEGIN balance(:cardnumber,:trnam ntstr); END;';
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':c ardnumber' ,&$cardnum ber,32);
oci_bind_by_name($stmt,':t rnamntstr' ,&$trnamnt str,32);
$cardnumber = '52131111111111';
oci_execute($stmt);
print "$trnamntstr\n";
?>
<?php
$conn = oci_connect('abc', 'abc', 'test') or die('Cannot connect') ;
$sql = 'BEGIN balance(:cardnumber,:trnam
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,':c
oci_bind_by_name($stmt,':t
$cardnumber = '52131111111111';
oci_execute($stmt);
print "$trnamntstr\n";
?>
try this
use double quotes inseted of single quotes
oci_bind_by_name($stmt,":c ardnumber" ,&$cardnum ber,32);
oci_bind_by_name($stmt,":t rnamntstr" ,&$trnamnt str,32);
use double quotes inseted of single quotes
oci_bind_by_name($stmt,":c
oci_bind_by_name($stmt,":t
ASKER
The same ! :(
ASKER
Do you have any idea?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all!
ASKER
Hi hernst 42,
I folow your help , read the link and try new code.
By chance , i realize i have mistake when key in :cardnumber value
Wrong value makes nothing display.
and i don't know why and continue asking the experts :(
I am careful to input the value so the result display with the expected value.
Hi shajukg,
Your help is okie and run!
Thanks so much for your effort!
I am really sorry due to stupid typing that waste your time !
I folow your help , read the link and try new code.
By chance , i realize i have mistake when key in :cardnumber value
Wrong value makes nothing display.
and i don't know why and continue asking the experts :(
I am careful to input the value so the result display with the expected value.
Hi shajukg,
Your help is okie and run!
Thanks so much for your effort!
I am really sorry due to stupid typing that waste your time !
additional note:
the & might not be needed if you correctly define the variables before usage. So this might also work if you want to try. Would be intersting to know if that also works.
the & might not be needed if you correctly define the variables before usage. So this might also work if you want to try. Would be intersting to know if that also works.
$conn = oci_connect('abc', 'abc', 'test') or die('Cannot connect') ;
$sql = 'BEGIN balance(:cardnumber,:trnamntstr); END;';
$stmt = oci_parse($conn,$sql);
$cardnumber = '52131111111111';
$trnamntstr = null;
oci_bind_by_name($stmt,':cardnumber',$cardnumber,32);
oci_bind_by_name($stmt,':trnamntstr',$trnamntstr,32);
oci_execute($stmt);
print "$trnamntstr\n";
ASKER
hi hernst42,
You are correct !
It also works!
I forget to post it because i said that the error is due to my typing ....
you are great!
You are correct !
It also works!
I forget to post it because i said that the error is due to my typing ....
you are great!
$cardnumber = '5xxxxxxxxxxxxx';
and
add on eline after oci_execute
print "$cardnumber\n";