dongqiaogouk86049 2016-04-29 10:34
浏览 117

如何使用ODBC在PHP上调用oracle存储过程

I am trying to call an Oracle stored procedure at a PHP website using ODBC. I have a table named "employees". I want to see the total employee number at the website. Below I am describing the function, procedure and pl/sql to run normally from sql.

FUNCTION:

CREATE OR REPLACE FUNCTION func_totalEmployees 
RETURN number IS
t_emp number;
BEGIN
        select count(*) INTO t_emp from employees;
    RETURN t_emp;
END;

This function will count all entry at employees table. Then store the value at

t_emp

PROCEDURE:

CREATE OR REPLACE PROCEDURE pro_totalEmployees(totalEmployees OUT number) 
IS
BEGIN
    totalEmployees := func_totalEmployees;

END;

This procedure will run our function and output one value using totalEmployees variable.

PL/SQL:

DECLARE
see_totalEmployees number;
BEGIN
    pro_totalEmployees(see_totalEmployees);
        dbms_output.put_line('Total Employees you have: ' || see_totalEmployees);
END;

Now the execution part. This is just simple pl/sql query which output the total number of employees from our procedure using variable see_totalEmployees

That's it!

So at sql, I got the output: Total Employees you have: 107

NOW MY QUESTION:

How can I store this 107 into a PHP variable using ODBC?

Please Help. Thanks in advance

  • 写回答

1条回答 默认 最新

  • duanguo7021 2016-04-29 11:22
    关注

    You can try some thing like this,

        <?php
        $Tot_emp = 0;
    
        // Create connection to db
        $conn = odbc_connect('db_name','user_name','password') or die;
    
        // Call your procedure
        $stmt = $conn->prepare("CALL sp_returns_string(?)");
    
        // Bind the output parameter
        $stmt->bindParam(1, $Tot_emp, PDO::PARAM_STR, 4000);    
    
        // call the stored procedure
        $stmt->execute();        
    
        // $message is now populated with the output value
        print "$Tot_emp
    ";
        ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏