public function banIPs($desc, $ips, $permissionSet = 10) { $query = new Query('INSERT'); $query->intoTable('bans_ip'); $query->intoField('ban_desc'); $query->intoField('ip_low'); $query->intoField('ip_high'); $query->intoField('permissionset_id'); $query->intoField('date_banned'); foreach ($ips as $ip) { $intip = $this->toIntIP($ip); $query->values('(?, ?, ?, ?, NOW())', array($desc, $intip, $intip, $permissionSet)); } $stmt = $query->prepare(); return $stmt->execute(); }
public function insert($ignore = false) { $query = new Query('INSERT', $this->dbengine); if ($ignore) { $query->ignore(); } $query->intoTable(static::$tableNoPrefix); $vals = array(); $template = '('; foreach ($this->stored as $key => $val) { $valid = true; if ($key == static::$primaryKey && static::$primaryKeyIsAutoIncrement) { $valid = false; } if ($valid) { $query->intoField($key); if ($this->sqlkeys[$key]) { $template .= $val . ', '; } else { $template .= '?, '; $vals[] = $val; } } } if ($template == '(') { throw new NoStoredValuesException('INSERT cannot be completed: No values to be inserted.'); } $template = substr($template, 0, -2) . ')'; $query->values($template, $vals); $stmt = $query->prepare(); if (!$stmt->execute()) { $info = $stmt->errorInfo(); $e = new QueryFailedException($info[2]); $e->errorInfo = $info; throw $e; } return true; }
$name = $row['name']; $app_id = $row['id']; // Pull out the words we'll need to index $iwords = $am->getIndexable($name); // Add 'em if (count($iwords) > 0) { echo "Indexing: " . implode(', ', $iwords) . "<br />\n"; foreach ($iwords as $iword) { $sindex[$iword][] = $app_id; } } else { echo "No words to be indexed.<br />\n"; } } } echo "<br />Saving and caching:<br />\n"; foreach ($sindex as $term => $idarray) { echo "<strong>{$term}</strong> "; echo str_replace("\n", "<br />\n", print_r($idarray, true)); $cm->set("search_name_index:{$term}", $idarray, 0); $query = new Query('INSERT'); $query->intoTable('search_name_index'); $query->intoField('term'); $query->intoField('app_id_array'); $query->values("(?, ?)", array($term, serialize($idarray))); $stmt = $query->prepare(); if (!$stmt->execute()) { echo "Error while adding term '{$term}'.<br />\n"; } } echo "<br />Done!";