1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Why my AsyncTask doesn't work ?

Discussion in 'Development' started by Miste, May 8, 2017.

Thread Status:
Not open for further replies.
  1. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    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:
    <?php

    namespace 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)
     
    Last edited: May 8, 2017
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Do not store mysqli resources/objects to AsyncTask fields. Use getFromThreadStore/saveToThreadStore instead.

    You may also use libasynql for such operations.
     
  3. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    Can you give me an exemple of how to do it ? Without using libasynql librabry ?
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  5. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
  6. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    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.
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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?
     
    XdmingXD, HimbeersaftLP and Sandertv like this.
  8. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    Code to copy ? What code are you talking about ?
     
  9. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    HimbeersaftLP likes this.
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.