/** * create a new plane instance, optionally prefilled */ public function __construct($name, $db, $r = NULL) { $this->db = $db; if ($r === NULL) { $query = $this->db->prepare("\n SELECT name, first, last FROM planes\n WHERE replace(replace(lower(name), '_', ''), ' ', '') = ?\n LIMIT 1"); $query->execute([Toolkit::normalizeName($name)]); $r = $query->fetch(\PDO::FETCH_ASSOC); $query->closeCursor(); if ($r === False) { throw new Exception('No plane named ' . $name); } } $this->name = $r['name']; $this->first = $r['first']; $this->last = $r['last']; }
/** * search blocks by name */ public static function search($q, $db) { $query = $db->prepare("\n SELECT name, first, last FROM blocks\n WHERE replace(replace(lower(name), '_', ''), ' ', '') LIKE ?\n ORDER BY first ASC"); $query->execute([Toolkit::normalizeName("%{$q}%")]); $r = $query->fetchAll(\PDO::FETCH_ASSOC); $query->closeCursor(); $blocks = []; if ($r) { foreach ($r as $b) { $blocks[] = new static('', $db, $b); } } return $blocks; }
/** * search database by name */ public static function getByName($name, $db) { $query = $db->prepare("\n SELECT * FROM codepoints\n WHERE replace(replace(lower(na), '_', ''), ' ', '') = :name\n OR replace(replace(lower(na1), '_', ''), ' ', '') = :name\n LIMIT 1"); $query->execute([':name' => Toolkit::normalizeName($name)]); $r = $query->fetch(\PDO::FETCH_ASSOC); $query->closeCursor(); if ($r === False) { throw new Exception('No codepoint named ' . $name); } return new self($r['cp'], $db, ['properties' => $r]); }