Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get value by calling oracle function in PHP!

Posted on 2008-09-30
16
Medium Priority
?
1,894 Views
Last Modified: 2013-12-18
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 .
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;

Open in new window

0
Comment
Question by:dinhchung82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 2
16 Comments
 
LVL 15

Expert Comment

by:Shaju Kumbalath
ID: 22606580
i think u should remove the line
$cardnumber = '5xxxxxxxxxxxxx';

and
add on eline after oci_execute
print "$cardnumber\n";
 
 
0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22611001
$cardnumber = '5xxxxxxxxxxxxx';

This is the value that i pass to the ":cardnumber "

I cannot remove it
Thanks!

0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22611089
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,:trnamntstr); END;';
$stmt = oci_parse($conn,$sql);

oci_bind_by_name($stmt,':cardnumber',$cardnumber,32);
oci_bind_by_name($stmt,':trnamntstr',$trnamntstr,32);

$cardnumber = '5212345678991111';
oci_execute($stmt);
print "$trnamntstr\n";
?>


But the output is nothing ?
Would anybody have idea ?

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 15

Expert Comment

by:Shaju Kumbalath
ID: 22611789
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_output );
dbms_output.put_line(v_output);
end;
 
 
0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22611897
yes, the balance is okie and return the result .
But when call it from PHP page , i cannot receive the expected result.
Thanks
0
 
LVL 15

Accepted Solution

by:
Shaju Kumbalath earned 1600 total points
ID: 22612416
try adding  '&' in the following statements
 
oci_bind_by_name($stmt,':cardnumber',&$cardnumber,32);
oci_bind_by_name($stmt,':trnamntstr',&$trnamntstr,32);

 
0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22612429
I try this but nothing returns !!!!

<?php
$conn = oci_connect('abc', 'abc', 'test') or die('Cannot connect') ;
$sql  = 'BEGIN balance(:cardnumber,:trnamntstr); END;';
$stmt = oci_parse($conn,$sql);

oci_bind_by_name($stmt,':cardnumber',&$cardnumber,32);
oci_bind_by_name($stmt,':trnamntstr',&$trnamntstr,32);

$cardnumber = '52131111111111';
oci_execute($stmt);
print "$trnamntstr\n";

?>
0
 
LVL 15

Expert Comment

by:Shaju Kumbalath
ID: 22612543
try this
use double quotes inseted of single quotes
oci_bind_by_name($stmt,":cardnumber",&$cardnumber,32);
oci_bind_by_name($stmt,":trnamntstr",&$trnamntstr,32);


0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22612626
The same ! :(
0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22620944
Do you have any idea?
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 400 total points
ID: 22624737
Have you tried as SQL
$sql  = 'balance1(:cardnumber)';
Or have you read http://www.php.net/manual/en/function.oci-new-cursor.php
0
 
LVL 5

Author Closing Comment

by:dinhchung82
ID: 31501598
Thanks for all!
0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22625342
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 !
0
 
LVL 48

Expert Comment

by:hernst42
ID: 22625705
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.
$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";

Open in new window

0
 
LVL 5

Author Comment

by:dinhchung82
ID: 22625755
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question