我正在尝试使用 ODBC 和 PHP 检索 out 参数的值。我一直在网上搜索但无济于事。 PDO 和 mysqli 有很多解析,我只找到了 this对于 odbc。我有点迷失了参数和涉及的操作。
我可以连接到数据库,但总是弹出错误。我想不通。
[Sybase][ODBC Driver] Invalid string or buffer length
有什么建议吗?
<?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);
?>
最佳答案
现在我只是猜测,但如果实际查询中的 $UserId
和 $UserPwd
应该是列,请尝试删除 $-sign从他们。稍后在代码中,您试图将它们作为不带 $ 符号的列名获取,因此我不确定这是否是导致错误的原因。在 $UserId=odbc_result($rs,"UserId");
之前,它们不是 PHP 变量。
关于php - 使用 ODBC 和 PHP 检索存储过程的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41713186/