[MySql] How to createa new table and get things from it?

Discussion in 'Plugin Development' started by Minesuchtiiii, Sep 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Minesuchtiiii

    Hey, I'm coding a game which should use MySql.
    I have a MySql database and tried to connect with it, which successfully worked.
    But now I want to create a new tavle with 2 things: playername | coins
    Can anyone explain me how to create a table and how i get the int coins from the database?
    so for example if i want send the player how many coins he has how would i get the coins?
    p.sendMessage("You have" + ? + " coins");

    Thanks to everyone!
     
  2. Offline

    Halginzz

    Minesuchtiiii

    Send a SQL query.

    Create table example
    PHP:
    CREATE TABLE IF NOT EXISTS `databaseName`.`tablename` (`idINT NOT NULL AUTO_INCREMENT,`playerNameVARCHAR(16NOT NULL,`coinsINT NOT NULL,PRIMARY KEY (`id`));
    Get value example
    PHP:
    SELECT coins FROM tableName WHERE playerName='" + p.getName() + "';
     
  3. Offline

    Minesuchtiiii

    Halginzz
    this doesnt work to get a playername anymore, its needed to get a players uuid and save them too

    Why soo much stuff that i dont need?

    Code:java
    1. CREATE TABLE IF NOT EXISTS `databaseName`.`tablename` (`id` INT NOT NULL AUTO_INCREMENT,`playerName` VARCHAR(16) NOT NULL,`coins` INT NOT NULL,PRIMARY KEY (`id`));
     
  4. Offline

    Halginzz

  5. Offline

    Minesuchtiiii

Thread Status:
Not open for further replies.

Share This Page