<?php
 class vB_dB_Query_Stored extends vB_dB_Query { public function setQuery(array $params, array|string $sortorder) : bool { if (!isset($this->query_data[$this->queryid])) { throw new vB_Exception_Assertor('invalid_query_definition_x', $this->queryid); } unset($params[self::TYPE_KEY]); $this->params = $params; $this->data_loaded = true; return true; } public function execSQL() : mixed { if (!$this->data_loaded) { throw new vB_Exception_Assertor('invalid_query_definition_x', $this->queryid); } $query_string = $this->query_data[$this->queryid]['query_string']; $forcetext = $this->query_data[$this->queryid]['forcetext'] ?? []; if (!is_array($forcetext)) { $forcetext = [$forcetext]; } $queryBuilder = self::$queryBuilders[$this->db_type]; $query_string = $queryBuilder->matchValues($this->queryid, $query_string, $this->params, $forcetext); if (!$query_string) { return false; } $this->logQuery($query_string); $query_type = $this->query_data[$this->queryid][self::QUERYTYPE_KEY]; if ($query_type == self::QUERY_SELECT) { $useSlave = ($this->dbSlave AND empty($this->params[self::PRIORITY_QUERY])); $resultclass = 'vB_dB_' . $this->db_type . '_result'; $result = new $resultclass($this->db, $query_string, $useSlave); return $result; } else { $this->db->query_write($query_string); $error = $this->db->error(); if (!empty($error)) { throw new Exception($error); } switch($query_type) { case self::QUERY_DELETE: case self::QUERY_DROP: case self::QUERY_ALTER: case self::QUERY_UPDATE: return $this->db->affected_rows(); break; case self::QUERY_INSERT: return $this->db->insert_id(); break; case self::QUERY_CREATE: return true; break; } } throw new vB_Exception_Assertor('invalid_query_definition_x', $this->queryid); } } 