/** * @param string $query */ public final function __construct($sql, $connectionName = 'main') { if (preg_match(static::$queryTypeRegexp, $sql) != 1) { throw new WrongQueryTypeException("The query type '" . get_class($this) . "' is not intended for that query."); } $this->sql = $sql; $this->mysqli = Connection::getInstance($connectionName)->mysqli; }
/** * * Constructor for all inheriting statements. This behaviour should be the * same for every inheriting class, which is why it is final. * @param string $query * @param string $types * @throws MySQLi_Classes\Exceptions\ParameterCountMismatchException * @throws MySQLi_Classes\Exceptions\ErrorException */ public final function __construct($sql, $paramTypes = null, $connectionName = 'main') { if (preg_match(static::$queryTypeRegexp, $sql) != 1) { throw new WrongQueryTypeException("The query type '" . get_class($this) . "' is not intended for that query."); } $this->sql = $sql; $this->mysqli = Connection::getInstance($connectionName)->mysqli; $this->statement = $this->mysqli->prepare($this->sql); if ($this->mysqli->errno > 0) { throw ErrorException::findClass($this->mysqli, __LINE__); } if ($paramTypes == null) { $paramTypes = ''; } if ($this->statement->param_count != strlen($this->paramTypes = $paramTypes)) { throw new ParameterCountMismatchException('There is a mismatch between the number of statement variable types and parameters.'); } }