コード例 #1
0
 public function __construct(PluginBase $owner)
 {
     $cf = $owner->getCfg("MySql");
     $this->database = new \mysqli($cf["host"], $cf["user"], $cf["password"], $cf["database"], $cf["port"]);
     if ($this->database->connect_error) {
         throw new \RuntimeException("Invalid MySql settings");
         return;
     }
     $sql = "CREATE TABLE IF NOT EXISTS Scores (\n\t\t\tplayer VARCHAR(16) NOT NULL,\n\t\t\ttype VARCHAR(128) NOT NULL,\n\t\t\tcount INT NOT NULL,\n\t\t\tPRIMARY KEY (player,type)\n\t\t)";
     $this->database->query($sql);
     $owner->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($owner, [$this, "pingMySql"]), 600);
     $owner->getLogger()->info("Connected to MySQL server");
 }