Retrieving stored procedure data using ODBC and PHP

I am trying to get out parameter values ​​using ODBC and PHP. I searched online, but to no avail. There are many permissions for PDO and mysqli, and I found this one for odbc. I partially lose this parameter and engage the operation.

I can establish a database connection, but the error always appears. I could not understand them.

[Sybase] [ODBC driver] Invalid line 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); ?> 
+7
sql php odbc sqlanywhere
source share
2 answers

I finally found a solution.

I have a lot of misconception about a stored procedure when you return to the data for this question. Even the simplest.

Instead of retrieving the data of the called parameters, the called parameter is used to call other parameters of the result. For example, UserId and UserPwd are called here to display UserName and LoginStatus .

This is the correct code to extract data from the result parameter UserName and LoginStatus and based on the variable parameter UserId and UserPwd .

 <?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"); } 
+1
source share

Now I just guess, but if $UserId and $UserPwd in the actual query should be columns, try removing $ -sign from them. Later in the code, you try to get them as column names without $ -sign, so I'm not sure if this is causing an error. They are not PHP variables until $UserId=odbc_result($rs,"UserId"); .

+1
source share

All Articles