Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Mysql

Comments in 'Plugin Development' started by JackboyPlay, Feb 13, 2016.

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

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    and must i create a table for each Player when yes how?
    And Sorry for this much dump questions but i work for the first time with databases like mysql
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Sorry for the late reply, but @AndrewBit either use object-oriented style ONLY or use procedural style ONLY. Don't mix both together, or it will crash.
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @PEMapModder can you help me with the tables? Did you have an plugin example from github?
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Did I Need a Mysql PORT?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    MySQL port is 3306 by default, depending on your actual MySQL server port.

    Wait, do you even have a MySQL server setup?
    PocketKiller, KubixQ and applqpak like this.
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Yes of Course it was a bit embarrasign [Peinlich] if i haven't
    PEMapModder likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Just in case :p
    Then you don't need to specify the port, unless your server is not hosted on port 3306.
  8. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @PEMapModder Sorry but I am a bit too dump I dont know how to make for each Player the kills
    Franz: 1Kill
    Bernd: 3Kills
  9. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Check with EntityDamageByEntityEvent when a player kill another one and add to him 1 kill...
  10. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    ok
  11. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    $this->getDatabase()->query("UPDATE table SET punkte=punkte-1 WHERE name=" . $victim->getName()) ;
    $this->getDatabase()->query("UPDATE table SET punkte=punkte+1 WHERE name=" . $mörder->getName());

    case "punkte":
    $getting_info = $this->getDatabase()->query("SELECT punkte FROM spieler WHERE name='$sender->getName()'");
    $sender->sendMessage("§aDu hast §e" . $getting_info[2] . " §aPunkt(e)"); $getting_info = mysqli_fetch_row($getting_info);



    notice> UndefinedPropertyException: "Undefined property: pocketmine\Player::$getName" (E_NOTICE) in"/NickName/src/JackboyPlay/Nick/Main" at line 85 Unhandled exception executing command 'coins' in coins: Undefined property: pocketmine\Player::$getName
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't execute a query every time a player kills. You will end up having a very laggy server.
    In strings, if you want to do variable expanding (like "$abc") with function calls on an object, you must use curly braces.
    E.g.
    PHP:
     "WHERE name='{$sender->getName()}'"
    AndrewBit likes this.
  13. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Or
    PHP:
    " WHERE name='" $player->getName() . "'"
  14. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @PEMapModder can you correct it?
    I dont know what do you mean exactly!:)
  15. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    PHP:
    $this->getDatabase()->query("UPDATE table SET punkte=punkte-1 WHERE name='{$victim->getName()}'");
    $this->getDatabase()->query("UPDATE table SET punkte=punkte+1 WHERE name='{$mörder->getName()}'");
    // [...]
    case "punkte":
    $getting_info $this->getDatabase()->query("SELECT punkte FROM spieler WHERE name='{$sender->getName()}'");
    And, no, I'm not @PEMapModder.

    You can also do it with a concatenated string.
    PHP:
    $this->getDatabase()->query("UPDATE table SET punkte=punkte-1 WHERE name='" $victim->getName() . "'"/* Added ' ' */;
    $this->getDatabase()->query("UPDATE table SET punkte=punkte+1 WHERE name='" $mörder->getName() . "'" /* Added ' ' */;
    // [...]
    case "punkte":
    $getting_info $this->getDatabase()->query("SELECT punkte FROM spieler WHERE name='" $sender->getName() . "'");
    Last edited: Feb 14, 2016
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Compare:

    As for the lag problem, use AsyncTask to do that. Refer to HereAuth for example how to use MySQL through AsyncTask.
  17. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Ok and Sorry for what {} that? And Sorry I'm only 13...
  18. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    It separate the SQL from the PHP sentence.
    Also, the age is only a number, @PocketKiller is younger than you a he's a good developer...
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It escapes a PHP object method call from a string literal.
  20. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Ok thanks :D
Thread Status:
Not open for further replies.

Share This Page

Advertisement