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

Save players to database

Comments in 'Plugin Development' started by Deathcrow, Sep 20, 2015.

  1. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    Hey :D sorry i post a lot im a needy person(as my gf says)

    Anyways ik how to connect to a database in PHP would it be the same when making a plugin?

    What i would like to do is save players,how much money they have,invetory(in blockids), and last login time on my database

    If i was to do this on a website with users this would be fairly simple task but it seems to me evrything on pocketmine plugins is 10 times harder :(

    EDIT:
    To better explain why im wanting to do this

    I wanna record all this on my database because i am planning on making a leaderboard based on money and such on my website(which i can handle) I learned web developement not this XD so any help is appreciated
    Last edited: Sep 20, 2015
  2. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    Well im used to using it with HTML for web designing like this is what i would use to connect to my database
    PHP:
    $dbhost "localhost";
    $dbname "my_deathcrow";
    $dbuser "deathcrow";
    $dbpass "*********";
    mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " mysql_error());
    Of course this would be if it was on my server but if its not i would have changed
    PHP:
    $dbhost "localhost";
    to
    PHP:
     $dbhost "fdb13.biz.nf";
    that way it would actually connect and if i needed info from the database i would use a SQL query
  3. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Instead of mysql_connect(), use:
    PHP:
    new \mysqli($host$username$password$database);
    CrazedMiner and EvolSoft like this.
  5. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PEMapModder and CrazedMiner like this.
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Don't use MySQL functions anymore!
    It's deprecated and it will be removed. Use PDO or MySQLi instead.
    CrazedMiner likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    And BTW, if you are going to use biz.nf's database I suggest you don't. I tried it and it almost did not work. So laggy too.

Share This Page

Advertisement