note 50453 deleted from function.odbc-exec by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 10:15:40 +0000 |
| Subject: | note 50453 deleted from function.odbc-exec by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196950@lists.php.net to get a copy of this message | ||
Note Submitter: mramirez at star-dev dot com
----
Hi, I was trying to execute an stored procedure with
PHP 4.3.10 and MS SQL Server 6.5 using PHP function
"odbc_exec" and ODBC.
The problem was that it returned an ouput parameter
and didn't know the right PHP functions and SQL
syntax to call it.
Finally after looking elsewhere, it worked this way:
<html>
<title>test.php</title>
<body>
<?php
$server = 'myservername';
$database = 'mydatabasename';
$username = 'myusername';
$password = 'mypassword';
$connection_string =
'DRIVER={SQL SERVER};SERVER=' . $server . ';DATABASE=' . $database;
$connection = odbc_connect($connection_string, $username, $password);
$sql = "BEGIN ";
$sql .= " declare @MyOutputValue int ";
$sql .= " execute MyStoredProc @MyOutputValue output select @MyOutputValue ";
$sql .= "END ";
echo '<form>' . chr(13);
echo '<table border="1">' . chr(13) . chr(13);
echo '<tr>';
echo '<td><b>Valor</b></td>';
echo '</tr>';
$query = odbc_exec($connection, $sql);
while(odbc_fetch_row($query))
{
echo '<tr>' . chr(13);
// "odbc_result" = "FieldByNumber(Index)",
// "Index" starts with 1 not 0 !!! :
$returnvalue = odbc_result($query, 1);
echo '<td>' . $returnvalue . '</td>';
echo '</tr>' . chr(13);
echo chr(13);
}
echo '</table>' . chr(13);
echo '</form>' . chr(13);
odbc_free_result($query);
odbc_close($connection);
?>
</body>
</html>
Good Luck.