Hi, I am making an AsyncTask to do some MySQL stuff but it doesn't work. Can someone help me ? The connection works (to mysql). PHP: <?phpnamespace misteboss\pvp\task\AsyncTask;use pocketmine\scheduler\AsyncTask;use pocketmine\Server;use misteboss\pvp\Main;class UpdateProfileTask extends AsyncTask{public $bdd;public $clientId;public $adress;public $date;public $serveur;public $device;public $name; public function __construct($bdd, $clientId, $adress, $date, $serveur, $device, $name){ $this->bdd = $bdd; $this->clientId = $clientId; $this->adress = $adress; $this->date = $date; $this->serveur = $serveur; $this->name = $name; } public function onRun(){ $this->bdd = @mysqli_connect('127.0.0.1', 'root', 'password', 'GloriousFight', '3306'); if(!$this->bdd) { echo "Unable to connect to MySQL"; return; } mysqli_query($this->bdd, "UPDATE Joueurs SET UUID = $this->clientId WHERE IGN='$this->name'"); mysqli_query($this->bdd, "UPDATE Joueurs SET LastIP = $this->adress WHERE IGN='$this->name'"); mysqli_query($this->bdd, "UPDATE Joueurs SET LastJoin = $this->date WHERE IGN='$this->name'"); mysqli_query($this->bdd,"UPDATE Joueurs SET Device = $this->device WHERE IGN='$this->name'"); mysqli_query($this->bdd, "UPDATE Joueurs SET Serveur ='$this->serveur' WHERE IGN='$this->name'"); }} Error : Code: Warning: mysqli_query(): Couldn't fetch mysqli in /home/BuildUHC/plugins/Core(BuildUHC)/src/misteboss/pvp/task/AsyncTask/UpdateProfileTask.php on line 36 Warning: mysqli_query(): Couldn't fetch mysqli in /home/BuildUHC/plugins/Core(BuildUHC)/src/misteboss/pvp/task/AsyncTask/UpdateProfileTask.php on line 37 Warning: mysqli_query(): Couldn't fetch mysqli in /home/BuildUHC/plugins/Core(BuildUHC)/src/misteboss/pvp/task/AsyncTask/UpdateProfileTask.php on line 38 Warning: mysqli_query(): Couldn't fetch mysqli in /home/BuildUHC/plugins/Core(BuildUHC)/src/misteboss/pvp/task/AsyncTask/UpdateProfileTask.php on line 39 Warning: mysqli_query(): Couldn't fetch mysqli in /home/BuildUHC/plugins/Core(BuildUHC)/src/misteboss/pvp/task/AsyncTask/UpdateProfileTask.php on line 40 Thanks for help (@Muqsit @SOFe)
Do not store mysqli resources/objects to AsyncTask fields. Use getFromThreadStore/saveToThreadStore instead. You may also use libasynql for such operations.
Then look at the source of libasynql. https://github.com/poggit/libasynql/blob/master/libasynql/src/libasynql/QueryMysqlTask.php
The easiest thing to do would be to base the code for connecting to MySQL on the source of libasynql. Or just use libasynql for the plugin.
It is already very easy. If you want it to be easy, throw your computer out of the window (make sure no creatures are outside first) and ask someone else to make it for you. What I gave you was almost code to copy. What else do you want?