Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving Data of Stored Procedure Using ODBC and PHP

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);
?>
like image 903
Iman Yasmin Avatar asked Jan 18 '17 07:01

Iman Yasmin


1 Answers

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");.

like image 51
user2620460 Avatar answered Nov 03 '22 21:11

user2620460