/** * {@inheritdoc} */ public function find($string, $prefix = true, $limit = 20) { if ($prefix) { $escaped = db_like($string) . '%'; } else { $escaped = '%' . db_like($string) . '%'; } $map = $this->db->select('node', 'n')->fields('n', ['nid', 'title'])->condition('n.type', $this->bundle)->condition('n.title', $escaped, 'LIKE')->orderBy('n.title')->range(0, $limit)->execute()->fetchAllKeyed(); $ret = []; foreach ($map as $id => $title) { $ret[] = new EntityFinderResult('node', $id, $title, $this->getLabel()); } return $ret; }
/** * {@inheritdoc} */ public function loadWithConditions($conditions) { $q = $this->db->select('umenu', 'um')->fields('um'); foreach ($conditions as $key => $value) { $q->condition('um.' . $key, $value); } $r = $q->execute(); $r->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, Menu::class); $ret = []; while ($menu = $r->fetch()) { $ret[$menu->getName()] = $menu; } return $ret; }
function getStudentIds() { $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $sql = "SELECT id FROM students"; $string = array(); $res = $db->select($sql, $string, false, ''); return $res; }
function addNewStudent($login_code, $name, $birth, $pass, $email, $pn, $city, $subj) { $sql = "INSERT INTO teachers VALUES ('', ?, ?, ?, ?, ?, ?, ?)"; $string = array($login_code, $name, $birth, $pass, $email, $pn, $city); $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $db->queryWithoutResult($sql, $string, true, "sssssss"); $sql = 'SELECT id FROM teachers WHERE code = ?'; $string = array($login_code); $res = $db->select($sql, $string, true, 's'); $sql = "INSERT INTO teacher_subj VALUES (?,?)"; $string = array($res[0]['id'], $subj); $db->queryWithoutResult($sql, $string, true, "is"); return true; }
function addNewStudent($login_code, $name, $birth, $resi, $pass, $email, $ppn, $year, $class, $s_hostel, $allowance) { $sql = "INSERT INTO students VALUES ('', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $string = array($login_code, $name, $birth, $resi, $s_hostel, $allowance, $pass, $email, $ppn, $year, strtolower($class)); $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $db->queryWithoutResult($sql, $string, true, "ssssiisssis"); $sql = 'SELECT id FROM students WHERE login_code = ?'; $string = array($login_code); $res = $db->select($sql, $string, true, 's'); $zero = mt_rand(0, 18); $sql = "INSERT INTO misses VALUES (?,?)"; $string = array($res[0]['id'], $zero); $db->queryWithoutResult($sql, $string, true, "ii"); return true; }
public static function getSubjectIds() { $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $sql = "SELECT id FROM subjects"; $string = array(); return $db->select($sql, $string, false, ''); }
public function getMisses() { $id = $this->getId(); $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $sql = "SELECT number FROM misses WHERE id = ?"; $string = array($id); $res = $db->select($sql, $string, true, 'i'); return $res[0]['number']; }
/** * {@inheritdoc} */ public function pathHasMatchingAlias($initial_substring) { $query = $this->db->select('url_alias', 'u'); $query->addExpression(1); return (bool) $query->condition('u.source', $this->db->escapeLike($initial_substring) . '%', 'LIKE')->range(0, 1)->execute()->fetchField(); }
public function getSubject($id) { $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $sql = "SELECT name FROM subjects WHERE id = ?"; $string = array($id); $res = $db->select($sql, $string, true, 'i'); return $res[0]['name']; }
public function select($table, $alias = NULL, array $options = array()) { return $this->connection->select($table, $alias, $options); }
/** * @see DatabaseConnection::select */ public function select($columns = '*', $where = '', $whereArgs = array(), $orderBy = null, $limit = null) { return $this->dbc->select($this->tblname, $columns, $where, $whereArgs, $orderBy, $limit); }