使用ODBC和PHP检索存储过程的数据

Ima*_*min 7 php sql odbc sqlanywhere

我正在尝试使用ODBC和PHP检索out参数的值.我一直在网上搜索但无济于事.PDO和mysqli有很多解析,我只为odbc 找到了这个.我有点迷失参数和操作涉及.

我能够建立与数据库的连接,但总是弹出错误.我无法理解它们.

[Sybase] [ODBC驱动程序]无效的字符串或缓冲区长度

有什么建议吗?

<?php

$conn=odbc_connect("dsn", " ", " ");

if (!$conn)
{
exit("Connection Failed: " . $conn);
}

$sql=odbc_prepare("CALL ndTblUser (@varUserId,@varUserPwd)"); 
$stmt=odbc_execute($sql, "SELECT @varUserId as UserId, @varUserPwd as UserPwd");

$rs=odbc_exec($conn,$stmt);

if (!$rs)
{
exit("Error : " . odbc_errormsg());
}
echo "<table><tr>";
echo "<th>Id</th>";
echo "<th>Password</th></tr>";

while (odbc_fetch_row($rs))
{
$UserId=odbc_result_all($rs,"UserId");
$UserPwd=odbc_result_all($rs,"UserPwd");
echo "<tr><td>$UserId</td>";
echo "<td>$UserPwd</td></tr>";
}

odbc_close($conn);
?>
Run Code Online (Sandbox Code Playgroud)

Ima*_*min 1

我终于找到了解决方案。

在检索这个问题的数据时,我对存储过程有很多误解。即使是最简单的一个。

被调用参数不是检索被调用参数的数据,而是用于调用其他结果参数。例如,这里调用UserIdandUserPwd来显示UserNameand LoginStatus

这是基于and的变量参数检索结果参数UserName和的数据的正确代码。LoginStatusUserIdUserPwd

<?php

$conn=odbc_connect("dsn", " ", " ");

if (!$conn)
{
  exit("Connection Failed : " . $conn);
}

$stmt=odbc_exec($conn,"CALL ndTblUser (".$_POST['UserId'].",'".$_POST['UserPwd']."')");

if (!$stmt)
{
  "Error : " . odbc_errormsg();
}

if (odbc_fetch_row($stmt))
{
  $UserName=odbc_result($stmt,"UserName");
  $LoginStatus=odbc_result($stmt,"LoginStatus");
}


if($LoginStatus==1)
{
  echo odbc_result($stmt,"UserName");
  echo odbc_result($stmt,"LoginStatus");
}
Run Code Online (Sandbox Code Playgroud)