note 17806 added to function.mssql-execute
| From: | fjortizATcomunetDOTes at php2 dot chek dot com | Date: | Wed, 26 Dec 2001 11:01:00 +0000 |
| Subject: | note 17806 added to function.mssql-execute | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-23839@lists.php.net to get a copy of this message | ||
After initializing a stored procedure
with mssql_init, and binding all the
parameters (and return value if needed)
with mssql_bind, you can execute the
statement with mssql_execute.
Parameters:
- stmt: statement resource obtained with
mssql_init.
From here, you can use any of the other
mssql_* functions to retrieve the
recordsets as if you had called
mssql_query. Any T-SQL error will also
be reported in the same way. The
variables passed by reference for OUTPUT
and RETVAL parameters will be filled
with the right values.
Now, an example:
if we have this procedure:
CREATE PROCEDURE [procedure]
(
@sval varchar(50) OUTPUT,
@intval int OUTPUT,
@floatval decimal(6,4) OUTPUT
) AS
if @intval is null
select '@intval is null' as answer
else
select '@intval is NOT null' as answer
set @sval='Hello ' + @sval
set @intval=@intval+1
set @floatval=@floatval+1
return 10
We can use this PHP code:
<?php
$conn=mssql_connect("myhost","user","pwd");
if ($conn) {
mssql_select_db("mydb",$conn);
$stmt=mssql_init("procedure",$conn);
mssql_bind($stmt,"RETVAL",&$val,SQLINT4);
$ival=11;
$fval=2.1416;
$sval="Frank";
mssql_bind($stmt,"@sval",&$sval,SQLVARCHAR,TRUE);
mssql_bind($stmt,"@intval",&$ival,SQLINT4,TRUE);
mssql_bind($stmt,"@floatval",&$fval,SQLFLT8,TRUE);
$result=mssql_execute($stmt);
$arr=mssql_fetch_row($result);
print ("Answer: " . $arr[0] . "<br>" );
print ("RETVAL = $val ; intval = $ival ; floatval = $fval ; string = $sval");
mssql_close($conn);
}
else print("ooops!");
?>
Hope it helps. Good luck!
--
http://www.php.net/manual/en/function.mssql-execute.php
http://master.php.net/manage/user-notes.php?action=edit+17806
http://master.php.net/manage/user-notes.php?action=delete+17806
http://master.php.net/manage/user-notes.php?action=reject+17806