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

Solved MySQL error

Comments in 'Plugin Development' started by Andrey Nazarchuk, Aug 1, 2015.

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

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Hello,
    I searched the forums and did not find an answer to this error.
    When my plugin starts I get this error:
    Code:
    [Server thread/WARNING]: RuntimeException: "mysqli::mysqli(): (HY000/2002): No connection could be made because th" (E_WARNING) in "/SkyWars/src/SkyWars/SkyWars" at line 127
    
    [07:59:08] [Server thread/DEBUG]: #0 /SkyWars/src/SkyWars/SkyWars(127): mysqli->mysqli(string IP, string root, string Password, string Stats, integer 3306)
    
    [07:59:08] [Server thread/DEBUG]: #1 /src/pocketmine/plugin/PluginBase(86): SkyWars\SkyWars->onEnable()
    
    [07:59:08] [Server thread/DEBUG]: #2 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(125): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    
    [07:59:08] [Server thread/DEBUG]: #3 /src/pocketmine/plugin/PluginManager(562): FolderPluginLoader\FolderPluginLoader->enablePlugin(SkyWars\SkyWars object)
    
    [07:59:08] [Server thread/DEBUG]: #4 /src/pocketmine/Server__32bit(1973): pocketmine\plugin\PluginManager->enablePlugin(SkyWars\SkyWars object)
    
    [07:59:08] [Server thread/DEBUG]: #5 /src/pocketmine/Server__32bit(1959): pocketmine\Server->enablePlugin(SkyWars\SkyWars object)
    
    [07:59:08] [Server thread/DEBUG]: #6 /src/pocketmine/Server__32bit(1776): pocketmine\Server->enablePlugins(integer 1)
    
    [07:59:08] [Server thread/DEBUG]: #7 /src/pocketmine/PocketMine(464): pocketmine\Server->__construct(pocketmine\CompatibleClassLoader object, pocketmine\utils\MainLogger object, string phar://C:/Users/Nazarchuk/Downloads/PocketMine-MP/PocketMine-MP.phar/, string C:\Users\Nazarchuk\Downloads\PocketMine-MP\, string C:\Users\Nazarchuk\Downloads\PocketMine-MP\plugins\)
    
    [07:59:08] [Server thread/DEBUG]: #8 (1): require(string phar://C:/Users/Nazarchuk/Downloads/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    Here is Line 127:
    PHP:
      $this->db = new \mysqli($this->config->get("host"), $this->config->get("user"), $this->config->get("password"), $this->config->get("database"), $this->config->get("port"));
    Thank you for reading :)
  2. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Obviously connection to the database wasn't successful.
    PEMapModder likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Thats obvious :D
  4. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    But it ain't obvious to the user that posted this thread.
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Well, the error cuts off at "the" and MySQL database is up and everything, also it says because of line 127.
  6. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
  7. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    MySQL server is on. It has a different error when its off.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Maybe wrong password, or your MySQL user requires the client to connect from a certain IP that you aren't using.

    Try this:
    PHP:
    $mysql = @new \mysqli(...);
    var_dump($mysql->connect_error);
    This outputs the error correctly.
    Andrey Nazarchuk likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And there are many ways it isn't successful.
    Andrey Nazarchuk likes this.
  10. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    He didn't know the error, so I told him connection was unsuccessful.
  11. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Oh lol I forgot the @ sign before new \mysqli
    Thank you very much for your clear help :D
    Now it says it cant connect because the MySQL server is actively refusing the connection.
    I know this means I have to whitelist my IP, but idk where to find the file or command to do that.
  12. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Ok I got a friend to fix it, I just needed to connect to a user account other than the root account, then it allows any ip
  13. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Why do you need a @? Just asking...
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The best syntax to make a MySQLi connection:

    PHP:
    $mysqli = @new \mysqli(...);
    if(
    $mysqli->connect_error){
      
    $this->getLogger()->critical("MySQL failed to connect because $mysqli->connect_error");
      
    // do something when it fails, like suicide by $this->getServer()->getPluginManager()->disablePlugin($this);
    }
    Andrey Nazarchuk likes this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement