سؤال

I'm trying to store an array in the cache, however I'm getting the error:

md5() expects parameter 1 to be string, object given in

Here's the code:

function getList(){
        global $meminstance;

        $query = $this->connection->prepare("SELECT id FROM " . TBL_LIST . " ORDER BY name");
        $query_key = "KEY" . md5($query);
        $list = $meminstance->get($query_key);

        if (!$list){
            $query = $this->connection->query("SELECT id FROM " . TBL_LIST . " ORDER BY name");
            $list = $query->fetch(PDO::FETCH_ASSOC); 
            $meminstance->set($query_key, $list, 0, 600);
        }
        return $list;
    }

What does the error mean? What am I doing wrong?

هل كانت مفيدة؟

المحلول

You trying to md5 object instead of string. Also there is nothing to prepare.

Try this.

function getList(){
        global $meminstance;

        $sql = "SELECT id FROM " . TBL_LIST . " ORDER BY name";
        $query_key = "KEY" . md5($sql);
        $list = $meminstance->get($query_key);

        if (!$list){
            $query = $this->connection->query($sql);
            $list = $query->fetch(PDO::FETCH_ASSOC);
            $meminstance->set($query_key, $list, 0, 600);
        }
        return $list;
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top