如何获得MS SQL Strored Procedure返回值在PHP中使用PDO?
Simlpe例如如何获得MS SQL Strored Procedure返回值在PHP中使用PDO?
CREATE PROCEDURE [dbo].[InsertLoginInPHP] @login as nvarchar(50), @password as nvarchar(50), @resultOK as int, @resultnot as int
AS
BEGIN
SET @resultOK = 10
SET @resultnot = 1
IF EXISTS (SELECT * FROM Users WHERE Login = @login)
BEGIN
SELECT @resultnot as return // 1
END
ELSE
BEGIN
INSERT INTO Users (Login,Password) VALUES(@login,@password)
SELECT @resultOK as return // 10
END
END
自PHP
$query = ("EXECUTE InsertLogin :login, :password"); $query_stored = $conn->prepare($query);
$query_stored->bindvalue(':login', $login);
$query_stored->bindvalue(':password', $password);
$query_stored->execute();
我怎样才能在PHP返回值(@resultnot或@resultOK)? 而我怎样才能得到并使用JSON中的返回值? 这
json_encode(array('status'=>'Ok','return'=>$query_sotored[resultOK])));
感谢像...
回答:
你需要从语句读取行,然后从这个返回数组访问列。
$query = ("EXECUTE InsertLogin :login, :password"); $query_stored = $conn->prepare($query);
$query_stored->bindvalue(':login', $login);
$query_stored->bindvalue(':password', $password);
$query_stored->execute();
$row = $query_stored->fetch(PDO::FETCH_ASSOC);
echo json_encode(array('status'=>'Ok','return'=>$row['return'])))
以上是 如何获得MS SQL Strored Procedure返回值在PHP中使用PDO? 的全部内容, 来源链接: utcz.com/qa/267298.html