MatthiasMullie\Scrapbook\Adapters\MySQL::setMulti PHP Method

setMulti() public method

public setMulti ( array $items, $expire )
$items array
    public function setMulti(array $items, $expire = 0)
    {
        $i = 1;
        $query = array();
        $params = array();
        $expire = $this->expire($expire);
        foreach ($items as $key => $value) {
            $value = $this->serialize($value);
            $query[] = "(:key{$i}, :value{$i}, :expire{$i})";
            $params += array(":key{$i}" => $key, ":value{$i}" => $value, ":expire{$i}" => $expire);
            ++$i;
        }
        $statement = $this->client->prepare("REPLACE INTO {$this->table} (k, v, e)\n            VALUES " . implode(',', $query));
        $statement->execute($params);
        /*
         * As far as I can tell, there are no conditions under which this can go
         * wrong (if item exists or not, REPLACE INTO will work either way),
         * except for connection problems, in which case all or none will be
         * stored.
         * Can't compare with count($items) because rowCount could be 1 or 2,
         * depending on if REPLACE was an INSERT or UPDATE.
         */
        $success = $statement->rowCount() > 0;
        return array_fill_keys(array_keys($items), $success);
    }