I'm trying to retrieve values of out parameter by using ODBC and PHP. I've been searching online but to no avail. There are a lot of resolves for PDO and mysqli and I only found this for odbc. I'm kind of lost by the parameter and the operation involve.
I'm able to make the connection to the database but the error always pops up. I couldn't figure them out.
[Sybase][ODBC Driver] Invalid string or buffer length
Any suggestion?
<?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);
?>
Now I'm just about guessing, but if the $UserId
and $UserPwd
in the actual query is supposed to be columns, try to remove the $-sign from them. Later on in the code you're trying to get them as column names with out the $-sign, so I'm not sure if that's what's causing the error. They're not PHP variables until $UserId=odbc_result($rs,"UserId");
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With