Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- Class MySQL
- {
- // Connection of the mysql api
- Private $Connection ;
- // Database information
- Private $Hostname ;
- Private $Username ;
- Private $Password ;
- Private $Database ;
- // Last handles of query and row
- Private $HandleOfLastQuery ;
- Private $HandleOfLastRow ;
- // Methods to set and get the hostname
- Public Function GetHostname ( )
- {
- Return $this->Hostname ;
- }
- Public Function SetHostname ( $Hostname )
- {
- $this->Hostname = $Hostname ;
- }
- // Methods to set and get the username
- Public Function GetUsername ( )
- {
- Return $this->Username ;
- }
- Public Function SetUsername ( $Username )
- {
- $this->Username = $Username ;
- }
- // Methods to set and get the password
- Public Function GetPassword ( )
- {
- Return $this->Password ;
- }
- Public Function SetPassword ( $Password )
- {
- $this->Password = $Password ;
- }
- // Methods to set and get the database
- Public Function GetDatabase ( )
- {
- Return $this->Database ;
- }
- Public Function SetDatabase ( $Database )
- {
- $this->Database = $Database ;
- }
- // Method to initialize and connect to the
- // mysql server and database
- Public Function Initialize ( )
- {
- $this->Connection = MySQL_Connect ( $this->Hostname , $this->Username , $this->Password ) ;
- MySQL_Select_DB ( $this->Database , $this->Connection ) ;
- }
- // Method to finalize and close the
- // mysql server and database connection
- Public Function Finalize ( )
- {
- MySQL_Close ( $this->Connection ) ;
- }
- // Method to send a query to the
- // mysql server and database
- Public Function Query ( $Query )
- {
- $this->HandleOfLastQuery = MySQL_Query ( $Query , $this->Connection ) ;
- }
- // Method to fetch an object
- Public Function Fetch ( )
- {
- $this->HandleOfLastRow = MySQL_Fetch_Object ( $this->HandleOfLastQuery ) ;
- Return $this->HandleOfLastRow ;
- }
- // Method to get the row
- Public Function GetRow ( )
- {
- Return $this->HandleOfLastRow ;
- }
- // Method to get the number of rows
- Public Function GetNumberOfRows ( )
- {
- Return MySQL_Num_Rows ( $this->HandleOfLastQuery ) ;
- }
- } ;
- $MySQL = new MySQL ;
- $MySQL->SetHostname ( "xx" ) ;
- $MySQL->SetUsername ( "xx" ) ;
- $MySQL->SetDatabase ( "xx" ) ;
- $MySQL->SetPassword ( "xx" ) ;
- $pw1 = $_POST["pw"];
- $pw = md5($pw1);
- $user = $_POST["user"];
- if((($pw1 == "") and ($user == "")) or (($user == "Ihr Benutzername") and ($pw1 == "Ihr Kennwort")))
- {
- echo "Bitte das Formular ausfüllen";
- }
- else
- {
- $MySQL->Initialize ( ) ;
- $result = $MySQL->Query ( "SELECT id FROM cms_login WHERE benutzer LIKE '$user'" );
- $MySQL->Fetch ( ) ;
- $MySQL->Finalize ( ) ;
- if($result == 0)
- {
- $MySQL->Initialize ( ) ;
- $eintragen = $MySQL->Query ( "INSERT INTO cms_login (benutzer, passwort) VALUES ('$user', '$pw')" );
- $MySQL->Fetch ( ) ;
- $MySQL->Finalize ( ) ;
- if($eintragen == true)
- {
- echo "Benutzername <b>$user</b> wurde erstellt.";
- } else {
- echo "Fehler beim Speichern des Benutzernamens.";
- }
- } else {
- echo "Benutzername schon vorhanden!";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement