note 50453 added to function.odbc-exec
| From: | mramirez at star-dev dot com | Date: | Tue, 01 Mar 2005 00:24:02 +0000 |
| Subject: | note 50453 added to function.odbc-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85696@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.odbc-exec.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50453
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50453&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50453&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50453&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50453&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50453&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50453&report=yes
Search -- http://master.php.net/manage/user-notes.php