Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. public static string myConnectionString = "SERVER=localhost;" + "PORT=3307;" + "DATABASE=gt_mp_data;" + "UID=root;" + "PASSWORD=root;";
  2.     public static MySqlConnection connection;
  3.     public static MySqlCommand command;
  4.     public static MySqlDataReader reader;
  5.  
  6.     public Boolean PlayerExists(string username)
  7.     {
  8.         //Create new connection
  9.         connection = new MySqlConnection(myConnectionString);
  10.         //Create a new command
  11.         command = connection.CreateCommand();
  12.         //Set the command - Create a query
  13.         command.CommandText = "SELECT * FROM user";
  14.  
  15.         //Open connection
  16.         connection.Open();
  17.         //Tell the reader what to read
  18.         reader = command.ExecuteReader();
  19.         //While the reader is still reading
  20.         while (reader.Read())
  21.         {
  22.             //Select every 'socialClubName' from the table
  23.             //string name = reader.GetString("social_club_name");
  24.             //Check if the player with that name exists
  25.             //API.consoleOutput(name);
  26.             if (username == reader.GetString("Username"))
  27.             {
  28.                 //If a user exists with this name then close the connection and return true
  29.                 connection.Close();
  30.                 return true;
  31.             }
  32.         }
  33.         connection.Close();
  34.         return false;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement