当前位置: 代码迷 >> Informix >> php调用informix存储过程的有关问题
  详细解决方案

php调用informix存储过程的有关问题

热度:8319   发布时间:2013-02-26 00:00:00.0
php调用informix存储过程的问题
现在网上有很多php调用存储过程的说明,但是都是 php 调用sqlserver,oracle,mysql的,一个也没有看到 php 调用informix

一个informix存储过程一般是   sp_proc(var1,var2) returning ret3
 我现在要传递参数给sp_proc   var1 date类型 var2 char类型


        $begdate="2012-10-12"
                
        $stmt = $db->prepare("call sp_proc(?,?)");
$stmt->bindparam(1,$begate);
$stmt->bindParam(2,"1");
$stmt->execute();

以上代码不正确,那么正确的代码应该如何写呢?还有返回值如何获取呢? 
------解决方案--------------------------------------------------------
简单 示例
$result=ifx_query("execute procedure sp_mailsetup('$ID')",$conn);
 if($result)
 {
 $row=ifx_fetch_row($result,'NEXT');
 print $result['[Expr_1]'];
 print $result['[Expr_2]'];
 }
------解决方案--------------------------------------------------------
我刚开始接触php ,所以不太明白,特向您请教
 
 ifx_query --这个是否就是不用pdo了? 用了专用的连接库?
 能否使用PDO 连接,因为我们这里没有ifx的相关连接库,只有pdo的!

$result=ifx_query("execute procedure sp_mailsetup('$ID')",$conn); 

--这个 $conn是什么?是连接数据库的串吗?
--您举的这个例子中 sp_mailsetup 是否只有一个变量?
--若回来有2个变量那是否 $result=ifx_query("execute procedure sp_mailsetup('$ID','$DD')",$conn);

这个 $result 是返回值?
例子中又使用了 ifx_fetch_row($result,'NEXT') --是否是说,若返回一组数据的时候使用,若只返回一个值
就可以只用
如下写法
$result=ifx_query("execute procedure sp_mailsetup('$ID')",$conn);
echo $result;

-------------------------------
$result=ifx_query("execute procedure sp_mailsetup('$ID')",$conn);
if($result)
 {
 $row=ifx_fetch_row($result,'NEXT');
  
 
 print $result['[Expr_1]'];
 print $result['[Expr_2]'];
 }
------解决方案--------------------------------------------------------
我查找了一些文档  如下:其中第一个人提出了问题,最后一个人的意思是目前好像只有ids 10,11才支持php调用存储过程,ids9,并不支持。我们就是ids9估计是不行了。请有用过的给个意见?

[2010-02-19 08:26 UTC] ihabunek at gmail dot com
Description:
------------
I have a very similar problem when calling stored procedures. 

Server is IDS 11.50uc4 running on Debian. The problem is reproducable on both Windows and Linux clients running PHP 5.2.x (both CLI and Apache), PDO_INFORMIX 1.2.6 and Informix Client SDK 3.50.

The problem is when calling the following stored procedure:

CREATE PROCEDURE test_proc(
param varchar(10)
)
END PROCEDURE;

Reproduce code:
---------------
<?php
$db_url = "informix:host=tstdb; service=1526; database=buba; server=tstdb; CLIENT_LOCALE=hr_hr.1250; DB_LOCALE=hr_hr.1250";
$db = new PDO($db_url, '<user>', '<pass>');

$query = "EXECUTE PROCEDURE test_proc(:param)";
$args = array('param' => 'abc');

$db = new PDO($db_url, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $db->prepare($query);
$stmt->execute($args);
?>

Expected result:
  相关解决方案