php呼叫mssql儲存過程

yeahokay發表於2007-07-07
這裡給出實現方法,註釋就不多寫了,詳見php參考手冊[@more@]

sqlserver儲存過程

CREATE PROCEDURE ProcTest @id int, @name varchar(30) output CREATE PROCEDURE ProcTest @id int, @name varchar(30) output
AS
select @name=username from mm_user where id=@idselect @name=username from mm_user where id=@id
select * from mm_userselect * from mm_user

php實現程式碼:

$userId = 2; // test parameter $userId = 2; // test parameter
$userName; // test return value $userName; // test return value

$link = mssql_connect("192.168.1.38", "sa", "sa123456a") or die("Can't connect sql server"); $link = mssql_connect("192.168.1.38", "sa", "sa123456a") or die("Can't connect sql server");
mssql_select_db("mm_db", $link) or die("Select database failure"); mssql_select_db("mm_db", $link) or die("Select database failure");

$stmt = mssql_init("ProcTest", $link) or die("initialize stored procedure failure"); $stmt = mssql_init("ProcTest", $link) or die("initialize stored procedure failure");
mssql_bind($stmt, "@id", $userId, SQLINT4); mssql_bind($stmt, "@id", $userId, SQLINT4);
mssql_bind($stmt, "@name", $userName, SQLVARCHAR, true); mssql_bind($stmt, "@name", $userName, SQLVARCHAR, true);
$rs = mssql_execute($stmt, false); $rs = mssql_execute($stmt, false);

do { do {
while ($row = mssql_fetch_array($rs)) { while ($row = mssql_fetch_array($rs)) {
print $row["id"]." ------ ".$row["username"]." ------ ".$row["password"]." ------
"; print $row["id"]." ------ ".$row["username"]." ------ ".$row["password"]." ------
";
}
} while (mssql_next_result($rs)); } while (mssql_next_result($rs));

print "user name is: ".$userName; print "user name is: ".$userName;
?>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/786540/viewspace-925056/,如需轉載,請註明出處,否則將追究法律責任。

相關文章