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

Cannot insert data into database

Discussion in 'Facepalm' started by XdmingXD, Aug 9, 2017.

  1. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    PHP:
    public function onJoin(PlayerJoinEvent) {
    var_dump($this->plugin->getDatabase()); //SQLite3 object
    $this->plugin->getDatabase()->exec("INSERT INTO database (date , time , player) VALUES ('$date' , '$time' , '$name' ");
    }
    I am very upset... :facepalm:
    Code:
    2017-08-09 [13:22:21] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'WhatTheServer v1.0.0': Call to a member function exec() on null on test\eventmanager
    2017-08-09 [13:22:21] [Server thread/CRITICAL]: Error: "Call to a member function exec() on null" (EXCEPTION) in "test/src/test/eventmanager" at line 32
    
    Did I miss something?
     
    Last edited: Aug 9, 2017
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Can you show what code $this->plugin->getDatabase() runs? Because that's probably the place where something is going wrong.
    Also, inside your var_dump() you wrote $the instead of $this.
     
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    PHP:
    //main
    public $database;

    public function 
    getDatabase() {
            return 
    $this->database;
        }

    //database class
    class SQLiteDataProvider {
     
        private 
    $main$database;
         
        public function 
    __construct(main $plugin) {
            
    $this->main$plugin;
            if(!
    file_exists($this->main->getDataFolder() . "database.db")){
                
    $this->database = new \SQLite3($this->main->getDataFolder() . "database.db");
                
    $this->database->exec("CREATE TABLE IF NOT EXISTS database
                                                (id INTEGER PRIMARY KEY AUTOINCREMENT , date INTEGER , time INTEGER , player TEXT , level TEXT , x INTEGER , y INTEGER , z INTEGER , event TEXT , block TEXT , item_transfer TEXT , join_date INTEGER , last_online INTEGER);"
    );
            }
            
    $this->main->database $this->database;
        }
    EDIT : :facepalm:
    PHP:
    class SQLiteDataProvider {
     
        private 
    $main$database;
         
        public function 
    __construct(main $plugin) {
            
    $this->main$plugin;
            if(!
    file_exists($this->main->getDataFolder() . "database.db")){
                
    $this->database = new \SQLite3($this->main->getDataFolder() . "database.db");
                
    $this->database->exec("CREATE TABLE IF NOT EXISTS database
                                               (id INTEGER PRIMARY KEY AUTOINCREMENT , date INTEGER , time INTEGER , player TEXT , level TEXT , x INTEGER , y INTEGER , z INTEGER , event TEXT , block TEXT , item_transfer TEXT , join_date INTEGER , last_online INTEGER);"
    );
    $this->main->database $this->database;
            }
        }
    Problem fixed :(
     
    Last edited: Aug 9, 2017
  4. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Please move this thread to facepalm...
    Just ... leave me along... Biggest shame in my life....
     
    Last edited: Aug 9, 2017
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you also need to have a base provider if you want to switch between formats
    (someone should write a quality tutorial about it)
     
  6. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Agree : D
     
  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.