一聚教程网:一个值得你收藏的教程网站

PHP操作MSSQL存储过程修改用户密码

时间:2016-06-30 00:00:00 编辑:简简单单 来源:转载

mssql2008 存储过程 下面可以直接远程修改密码。

 代码如下

USE [GameUserDB]
GO
IF EXISTS (SELECT * FROM DBO.SYSOBJECTS WHERE ID = OBJECT_ID(N'[dbo].[UpdateUserInfo]') and OBJECTPROPERTY(ID, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[UpdateUserInfo]
GO
CREATE PROCEDURE [UpdateUserInfo]
 @dwUserID INT,
 @strCompellation NVARCHAR(16),
 @strQQ NVARCHAR(16),
 @strEmail NVARCHAR(32),
 @strSeatPhone NVARCHAR(32),
 @strMobilePhone NVARCHAR(16),
 @strDwellingPlace NVARCHAR(128),
 @strPostalCode NVARCHAR(8),
 @strUserNote NVARCHAR(256),
 @LogonPass char (32),
 @LogonPass2 char (32),
 @Typ NVARCHAR (50),
 @UserID INT,
 @FaceID INT
WITH ENCRYPTION AS
BEGIN
 IF @TYP='LostPass'
 BEGIN
  IF EXISTS (SELECT UserID FROM AccountsInfo WHERE UserID=@UserID And LogonPass=@LogonPass)
  BEGIN
   UPDATE [AccountsInfo]
   SET  LogonPass  = @LogonPass2 WHERE ( [UserID]  = @UserID)
   SELECT '成功信息:修改登入密码成功!'
  END
  ELSE
  BEGIN
   SELECT '您的原密码输入错误!'
  END
 END 
END
return 0
go

PHP操作存储过程

PHP调用存储过程修改用户密码,本示例直接填写参数,实际环境可以从外部程序提交数据进行处理。

 代码如下

<?php
/* 存储过程测试 */
//error_reporting(0);

/* 存储过程: 数据库连接
------------------------------------------------------*/
define('MSDB_HOST', '1.2.3.4');
define('MSDB_PORT', 1433);
define('MSDB_USER', 'yang');
define('MSDB_PASS', 'yangjunwei');
define('MSDB_NAME', 'GameUserDB');
$conn = mssql_connect(MSDB_HOST,MSDB_USER,MSDB_PASS) or die("SQL SERVER 数据库连接失败!");
mssql_select_db(MSDB_NAME);

/* 存储过程: 修改指定用户密码
------------------------------------------------------*/
$action_type = 'LostPass';  // 操作类型
$User_ID = 1;   //用户ID
$User_name = 'yang';  //用户名
$User_pass = md5("123456"); //原用户密码
$User_pass2 = md5("654321"); //新用户密码
$User_null = NULL;

$stmt = mssql_init("UpdateUserInfo", $conn) or die("initialize stored procedure failure");//初始化一个存储过程

mssql_bind($stmt, "@Typ", $action_type, SQLVARCHAR);
mssql_bind($stmt, "@UserID", $User_ID, SQLINT4);
mssql_bind($stmt, "@LogonPass", $User_pass, SQLCHAR);
mssql_bind($stmt, "@LogonPass2", $User_pass2, SQLCHAR);

mssql_bind($stmt, "@dwUserID", $User_null, SQLINT4, false, false);
mssql_bind($stmt, "@strCompellation", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strQQ", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strEmail", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strSeatPhone", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strMobilePhone", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strDwellingPlace", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strPostalCode", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@strUserNote", $User_null, SQLVARCHAR);
mssql_bind($stmt, "@FaceID", $User_null, SQLINT4);

/*
mssql_bind($stmt,"RETVAL",$val,SQLVARCHAR); //用于直接返回return -103此类的值。

$result = mssql_execute($stmt, true); //不能返回结果集,只能得到输出参数
echo $val.'<br />';
echo "This user id is: ".$UserID.'<br />';
echo "This user name is: ".$Accounts.'<br />';
*/

$result = mssql_execute($stmt,false); //返回结果集
$records=mssql_fetch_array($result);
print_r($records);
mssql_next_result($result); //下一个结果集,当等于FALSE的时候下一个就是输出参数

// MSSQL 调试
//die('MSSQL error: ' . mssql_get_last_message());
//exit;

?>

注释:MSSQL数据表大概设计

数据库:QPGameUserDB
数据表:AccountsInfo
数据列:UserID / LogonPass

文章评论

热门栏目