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

New API: How to work with MySQL in plugins

Comments in 'Plugin Development' started by luca28pet, Sep 2, 2014.

?

Do you think PocketMine should have documentations for these things?

Poll closed Sep 9, 2014.
  1. Yes, absolutely

    5 vote(s)
    45.5%
  2. No

    6 vote(s)
    54.5%
  1. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Hi coders, I 'm developing a private plugin for my server, that will use a simple mysql database to save stats of the server.I have a medium knowledge about queries, and working with php and mysql together, but I never did in pocketmine plugin, so I'm asking here because I think that the docs don't include this things, and all the plugins that I've seen use sqlite3 (similar but not the same).
    My questions are:
    • How do I generate the file that will contain the database?
    • How to execute basic queries?
    In normal php, they should be:
    • PHP:
      mysql_query("SELECT * FROM tab");   //(random query)
    and
    • PHP:
      mysql_query("CREATE  TABLE  tab1")
    I am not sure on how to do it in the PocketMine API..
  2. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    visit my profile. i have it in as a snippet

    edit:

    snippet link:
    http://pastebin.com/uygKGPtB

    config.yml:
    http://pastebin.com/4DtchvPP
    Jon and luca28pet like this.
  3. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Basically, PocketMine API doesn't affect MySQL since it is a function in an extension. However, PocketMine doesn't have the MySQL extension. It only has the MySQLi extension. Therefore, just change mysql_query() to mysqli_query(). Moreover, MySQL queries are sent to the MySQL server, not the MySQL extension itself. As a result, the MySQL syntax is the same everywhere unless your server is differnet.
    64FF00 and luca28pet like this.
  5. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    easy as pie :3
    64FF00 likes this.
  6. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    80
    Yes, you can use only msqli functions.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Who voted "Yes"? MySQLi is a PHP extension, and PocketMine is in no ways affiliated with it except PocketMine installer includes MySQLi. Since it is not a PocketMine feature, PocketMine should not have documentation on this. Instead, you should refer to the official MySQLi documentation on http://php.net for the most accurate documentation. However, again, MySQLi is not the MySQL language itself. MySQLi doesn't even have to parse the query you input. It just sends the query to the MySQL server and you should refer to the official MySQL website for MySQL information. In fact, the query language depends on which MySQL version the user uses to host the MySQL server, so as a plugin, you just need to tell the users what MySQL version it supports and you just need to support that version.
    Dutok and 64FF00 like this.
  8. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    80
    Yes, you are right. But I think that a small documentation should be included in PocketMine.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    OK. Tell PocketMine to add documentation for all functions and classes in PHP, and then for all extensions of PHP, and then all code that uses PHP, and then tell PocketMine to take over PHP development.
    Muqsit, TigerHix, Dutok and 1 other person like this.
  10. tnpxxsheepdog
    Offline

    tnpxxsheepdog Notable Member

    Joined:
    Dec 31, 2013
    Posts:
    356
    Minecraft User:
    TNPXXSHEEPDOG
    I have talked to few developers and they pretty much have no understanding on Mysql and how to integrate it. Hopefully some more documentation comes in.
  11. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Last edited: Sep 4, 2014
    PEMapModder likes this.
  12. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    an example of how to integrate MySQLi into plugins is:
    https://github.com/TuffDev/StaffTracker by @Tuff
    Praxthisnovcht likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That is what I was saying here:
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am noob at MySQL, but I won't ask for documentation from PocketMine because, why do you need another documentation when there is one existing already?

    This is just like the recently hotly debating universal suffrage issue in Hong Kong. Why do the citizens want universal suffrage so much? Is it that a government formed by universal suffrage is better than the current not-so-democratic way of electing the Chief Executive? Same with MySQL documentation. I don't think a PocketMine documentation of MySQL would be better than the one the MySQL organization/group/team/whatever made themselves.
    TigerHix likes this.
  15. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    i think they want examples how to use it? because documentation doesnt really answer the thing you wanted to do, except it gives you hints and guidelines.
  16. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    372
    Plugins:
    3
    Minecraft User:
    Dutok
  17. tnpxxsheepdog
    Offline

    tnpxxsheepdog Notable Member

    Joined:
    Dec 31, 2013
    Posts:
    356
    Minecraft User:
    TNPXXSHEEPDOG
    Dutok likes this.
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I see my discussion on the poll has changed the situation ;)
    Dutok likes this.
  19. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    Thank you for the answer!
    It is now working on x =
    Dutok likes this.

Share This Page

Advertisement