Forum Webscript.Ru

Общие => Веб-технологии => Тема начата: kwint от 24 Марта 2003, 13:58:07

Название: PHP И MS SQL
Отправлено: kwint от 24 Марта 2003, 13:58:07
Как вызывать хранимую процедуру MS SQL из PHP?
Заранее благодарен
Название: PHP И MS SQL
Отправлено: ThE0ReTiC от 24 Марта 2003, 23:12:41
mssql_execute()
смотрим мануал:
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:

$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] . "
" );
print ("RETVAL = $val ; intval = $ival ; floatval = $fval ; string = $sval");

mssql_close($conn);
}
else print("ooops!");
?>
Название: PHP И MS SQL
Отправлено: kwint от 25 Марта 2003, 12:34:46
Спасибо, удружил.
А где можно этот мануал достать?
Название: PHP И MS SQL
Отправлено: я... от 25 Марта 2003, 12:38:32
http://www.php.net