PHP operations MSSQL Stored procedures Modify user password

Source: Internet
Author: User
Tags md5 mssql stmt

The password can be modified directly under the mssql2008 stored procedure.

The code is as follows Copy Code

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 ' Success message: Modify login password successfully! '
End
ELSE
BEGIN
SELECT ' Your original password input error! '
End
End
End
return 0
Go

PHP Operation Stored Procedures

PHP calls stored procedures to modify the user password, this example directly fill in parameters, the actual environment can be submitted from the external Program data processing.

The code is as follows Copy Code

<?php
/* Stored Procedure Test/*
error_reporting (0);

/* Stored procedure: Database connection
------------------------------------------------------*/
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 database connection failed!") ");
mssql_select_db (Msdb_name);

/* Stored procedures: Modify the specified user password
------------------------------------------------------*/
$action _type = ' lostpass '; Type of action
$User _id = 1; User ID
$User _name = ' Yang '; User name
$User _pass = MD5 ("123456"); Original User Password
$User _PASS2 = MD5 ("654321"); New User Password
$User _null = null;

$stmt = Mssql_init ("Updateuserinfo", $conn) or Die ("Initialize stored procedure failure");//Initialize a stored procedure

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); Used to return the value of return-103 this class directly.

$result = Mssql_execute ($stmt, true); Cannot return result set, can only get output parameter
echo $val. ' <br/> ';
echo "This User ID is:". $UserID. ' <br/> ';
echo "This user name is:". $Accounts. ' <br/> ';
*/

$result = Mssql_execute ($stmt, false); return result set
$records =mssql_fetch_array ($result);
Print_r ($records);
Mssql_next_result ($result); Next result set, when equal to false, the next one is the output parameter

MSSQL debugging
Die (' MSSQL error: '. Mssql_get_last_message ());
Exit

?>

Note: MSSQL data tables are probably designed

Database: Qpgameuserdb
Data table: Accountsinfo
Data columns: Userid/logonpass

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.