|
You last visited: Today at 20:43
Advertisement
sqlsrv und output Parameter, hile benötigt.
Discussion on sqlsrv und output Parameter, hile benötigt. within the Web Development forum part of the Coders Den category.
04/13/2014, 13:52
|
#1
|
elite*gold: 0
Join Date: Feb 2012
Posts: 202
Received Thanks: 133
|
sqlsrv und output Parameter, hile benötigt.
Hallu :3
ich bin derzeit nen bissel mit SP's am rumhantieren. Als Server verwend ich den MS SQL Server 2008.
Was ich vor hatte: Das Login via Prozedur checken die einen rückgabewert liefert den ich dann im Script weiter auswerten kann.
SQL der SP:
Code:
/****** Object: StoredProcedure [dbo].[usp_login] Script Date: 04/13/2014 13:44:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_login]
@role varchar(30),
@password varchar(50),
@ip varchar(20),
@state nvarchar OUTPUT
as
SELECT
@state = COUNT(*) FROM dbo.ROLE_TBL
WHERE
role = @role AND password = @password
GO
Mein PHP Code enthält noch die IP des Benutzers, jedoch muss ich ja erst mal das eigentliche Login an sich zum Laufen bringen bevor ich etwas loggen kann. Die Prozedur gibt mir in meinen Managment Studio für das Output Field 1 oder 0 aus, also klappt die obrige Prozedur jedoch erhalte ich in PHP immer bei nen dump int(0) und errors werden mir auch nicht zurück gegeben.
PHP Code:
PHP Code:
public function chkLogin($role, $password) {
// Datenbank auf WEBSIT_DBF ändern
sqlsrv_query($this->db, "USE WEBSITE_DBF;");
// Login Prozedur setzen
$sql = "EXEC dbo.usp_login ?,?,?,?";
// SQL Parameter einbinden
$param = array(
array($role, SQLSRV_PARAM_IN),
array($password, SQLSRV_PARAM_IN),
array($_SERVER['REMOTE_ADDR'], SQLSRV_PARAM_IN),
array($output=0, SQLSRV_PARAM_OUT)
);
// SQL Prozedur ausführen
$stmnt = sqlsrv_query($this->db, $sql, $param);
// Fehler ausgeben lassen
if( $stmnt === false ) {
die( print_r( sqlsrv_errors(), true));
}
// Von der Prozedur den Output Wert zurückgeben.
return $output;
}
Ich arbeite erst seit kruzen mit den sqlsrv_ treibern und mit Prozeduren, kA ob ich irgendwo einen gravierenden Fehler habe, aber laut Dokumentation ist das so richtig.
lg und danke im vorraus für jede hilfe / jeden tipp.
|
|
|
04/14/2014, 13:42
|
#2
|
elite*gold: 0
Join Date: Apr 2010
Posts: 10,289
Received Thanks: 3,613
|
Kenne mich nicht wirklich mit sqlsrv aus, aber hat es einen Grund das output = 0 gesetzt wird und das auch erst in der Array?
Du könntest mal folgendes ausprobieren:
Code:
public function chkLogin($role, $password) {
// Datenbank auf WEBSIT_DBF ändern
sqlsrv_query($this->db, "USE WEBSITE_DBF;");
// Login Prozedur setzen
$sql = "EXEC dbo.usp_login ?,?,?,?";
$output = 0;
// SQL Parameter einbinden
$param = array(
array($role, SQLSRV_PARAM_IN),
array($password, SQLSRV_PARAM_IN),
array($_SERVER['REMOTE_ADDR'], SQLSRV_PARAM_IN),
array($output, SQLSRV_PARAM_OUT)
);
// SQL Prozedur ausführen
$stmnt = sqlsrv_query($this->db, $sql, $param);
// Fehler ausgeben lassen
if( $stmnt === false ) {
die( print_r( sqlsrv_errors(), true));
}
// Von der Prozedur den Output Wert zurückgeben.
return $output;
}
Lg
|
|
|
04/16/2014, 15:11
|
#3
|
elite*gold: 0
Join Date: Feb 2012
Posts: 202
Received Thanks: 133
|
Quote:
Originally Posted by Shawak
Kenne mich nicht wirklich mit sqlsrv aus, aber hat es einen Grund das output = 0 gesetzt wird und das auch erst in der Array?
Du könntest mal folgendes ausprobieren:
Code:
public function chkLogin($role, $password) {
// Datenbank auf WEBSIT_DBF ändern
sqlsrv_query($this->db, "USE WEBSITE_DBF;");
// Login Prozedur setzen
$sql = "EXEC dbo.usp_login ?,?,?,?";
$output = 0;
// SQL Parameter einbinden
$param = array(
array($role, SQLSRV_PARAM_IN),
array($password, SQLSRV_PARAM_IN),
array($_SERVER['REMOTE_ADDR'], SQLSRV_PARAM_IN),
array($output, SQLSRV_PARAM_OUT)
);
// SQL Prozedur ausführen
$stmnt = sqlsrv_query($this->db, $sql, $param);
// Fehler ausgeben lassen
if( $stmnt === false ) {
die( print_r( sqlsrv_errors(), true));
}
// Von der Prozedur den Output Wert zurückgeben.
return $output;
}
Lg 
|
Im Code an sich war kein Fehler. 
Die Prozedur war bissl komisch, mit nen Erzwingen ( T-sql Befehl RETURN ) des Anweisungsblock klappt nu alles, trotzdem danke Shawak
mfg
|
|
|
 |
Similar Threads
|
[RELEASE] SQLsrv PHP Tester
03/11/2014 - Dekaron Private Server - 4 Replies
This script can test your mssql connection and check if you have sqlsrv installed on php
Just edit this file ("sqlsrv_test.php") and upload to your server you want to check!
Have fun, and DONT forget to say Thanks!
|
[ADVANCED] Registration Script / SQLSRV
01/06/2014 - Rappelz Private Server - 30 Replies
-- Forewarning --
The following is in no way shape or form intended for the use of beginners and requires basic and intermediate skill levels to apply and use.
-- Features --
Username Check
Password Confirm
Password MD5 Encryption
Age Field (For Server using; Adult Server)
|
[RELEASE] SQLSRV Password Changer
11/26/2012 - Rappelz Private Server - 8 Replies
Warnings!
This script will only function with the following requirements met:
PHP 5.3+
SQLSRV api e.g PHP Driver 3.0+
Properly configured IIS 7.5+
Basic Knowledge of HTML/PHP
I will not be answering any questions and anything posted here-in will be provided on an as-is basis with the knowledge that you may have to make adaptations to the script to suit your specific needs.
|
[RELEASE] Simple SQLSRV Registration
11/26/2012 - Rappelz Private Server - 4 Replies
Warnings!
This script will only function with the following requirements met:
PHP 5.3+
SQLSRV api e.g PHP Driver 3.0+
Properly configured IIS 7.5+
Basic Knowledge of HTML/PHP
I will not be answering any questions and anything posted here-in will be provided on an as-is basis with the knowledge that you may have to make adaptations to the script to suit your specific needs.
|
[RELEASE]: SQLSRV Rappelz Website...
06/11/2012 - Rappelz Private Server - 1 Replies
Thanks to the FUNENTRY team for releasing the previuos version of this web site, here you can find its sqlsrv version...
Microsoft SQLSRV TechNote
Since mssql is going to be deprecated... enjoy this.
With regards,
Ska...
|
All times are GMT +1. The time now is 20:43.
|
|