Search code examples
phpmysqlexpressionengine

Fatal error: Call to a member function query() on a non-object expressionengine


I have no idea why this error is happening, it's shown in all the expressionengine tutorials and on the forums yet for some reason I still get it? line 43 is shown in the script

class upload_pictures
{
    public function upload_pictures()
    {
        if (!isset($whats_gonna_happen))
        {
            $uploads='';
            $cout=1;
            if (!table_exists('albums'))
            {
                                    //line 43 below
                $this->EE->db->query("CREATE TABLE albums(
                    id INT NOT NULL AUTO_INCREMENT,
                    PRIMARY KEY(id)
                    name VARCHAR(50)
                ") or die(mysql_error());
            }
            $stuff=$this->EE->db->query('SELECT id, name FROM albums');

Solution

  • I found the problem, it was in expressionengine you need to have the line

    $this->EE=& get_instance();

    in the constructor to get to the superglobals.