Execute a query with the passed options. Typically the options array will include a params subarray to run the
query as a prepared statement.

@param string $query_string
@param array $params
@param array $options
@return DAO
@throws \Exception
179038
public function query(string $query_string, array $params = [], array $options = []) : DAO
    {
        // Reset in case a previous query was attempted.
        $this->query_succeeded = false;

        // Connect to the database
        if (!$this->is_connected) {
            $this->connect();
        }

        try {
            $stmt = $this->getStatement($query_string);
            $this->stmt = $stmt;
            $stmt->execute($params);
        } catch (DatabaseQueryException $e) {
            throw $e;
        } catch (\Exception $e) {
            throw new DatabaseQueryException($e->getMessage() . '|| QUERY: ' . $query_string);
        }

        $this->query_succeeded = $this->stmt->querySucceeded();

        return $this;
    }
1184515
public function query(array $queryArgs, array $query = [], array $options = [])
    {
        $httpParams = [
            'query_parameters' => []
        ];
        $request = [
            'volatile' => $this->volatile
        ];

        if (array_key_exists('controller', $queryArgs)) {
            $request['controller'] = $queryArgs['controller'];
        } else {
            if (!array_key_exists('route', $queryArgs) || !array_key_exists('method', $queryArgs)) {
                throw new InvalidArgumentException('Unable to execute query: missing controller or route/method');
            }

            $request['controller'] = '';
        }

        if (array_key_exists('action', $queryArgs)) {
            $request['action'] = $queryArgs['action'];
        } else {
            if (!array_key_exists('route', $queryArgs) || !array_key_exists('method', $queryArgs)) {
                throw new InvalidArgumentException('Unable to execute query: missing action or route/method');
            }

            $request['action'] = '';
        }

        if (!empty($options)) {
            if (array_key_exists('volatile', $options)) {
                foreach ($options['volatile'] as $meta => $value) {
                    $request['volatile'][$meta] = $value;
                }
            }

            if (array_key_exists('requestId', $options)) {
                $request['requestId'] = $options['requestId'];
            }

            if (array_key_exists('httpParams', $options)) {
                foreach ($options['httpParams'] as $param => $value) {
                    $httpParams[$param] = $value;
                }
            }

            if (isset($options['query_parameters'])) {
                $httpParams['query_parameters'] = array_merge($httpParams['query_parameters'], $options['query_parameters']);
            }

            foreach (['refresh', 'from', 'size', 'scroll'] as $optionParam) {
                if (array_key_exists($optionParam, $options)) {
                    $httpParams['query_parameters'][$optionParam] = $options[$optionParam];
                }
            }
        }

        if (array_key_exists('volatile', $query)) {
            foreach ($query['volatile'] as $meta => $value) {
                $request['volatile'][$meta] = $value;
            }
        }

        foreach ($query as $attr => $value) {
            if ($attr === 'body' && empty($value)) {
                $request['body'] = (object)[];
            } else if ($attr !== 'volatile') {
                $request[$attr] = $value;
            }
        }

        $request = $this->addHeaders($request, $this->headers);

        /*
        * Do not add the token for the checkToken route, to avoid getting a token error when
        * a developer simply wish to verify his token
        */
        if ($this->jwtToken && !($request['controller'] === 'auth' && $request['action'] === 'checkToken')) {
            if (array_key_exists('headers', $request) && !is_array($request['headers'])) {
                $request['headers'] = [];
            }

            $request['headers']['authorization'] = 'Bearer ' . $this->jwtToken;
        }

        foreach (['collection', 'route', 'method', 'index'] as $queryArg) {
            if (array_key_exists($queryArg, $queryArgs)) {
                $request[$queryArg] = $queryArgs[$queryArg];
            }
        }

        if (!array_key_exists('requestId', $request)) {
            $request['requestId'] = Uuid::uuid4()->toString();
        }
         // @todo move this into RequestHandler
        return $this->emitRestRequest($this->convertRestRequest($request, $httpParams));
    }
797694
private function executeQuery($document, array $query, array $options)
    {
        $className  = get_class($document);
        $class      = $this->dm->getClassMetadata($className);
        $findQuery  = $this->getQueryForDocument($class, $document);
        $collection = $this->dm->getDocumentCollection($className);
        $collection->update($findQuery, $query, $options);
    }
1197018
function query($query,$bind_arr = null){
    $stmt = $this->mysqli->prepare($query);
    if(!$stmt){
     throw new Exception("can't prepare query:[$query] because [".$this->mysqli->error."]");
    }
    if(isset($bind_arr) && $bind_arr != null){
      call_user_func_array(array($stmt,'bind_param'),$this->makeValuesReferenced($bind_arr));
    }
    /* execute prepared statement */
    if(!$stmt->execute()){
       throw new Exception( $this->mysqli->error );
    }
    $answer = $this->fetch($stmt);
    $stmt->close();
    return $answer;
  }
755094
public static function process(string $model, \Numbers\Backend\Db\Common\Query\Builder & $query, array $options = []) {
		if (!self::can($model)) return false;
		foreach (self::$cached_models[$model] as $k => $v) {
			$object = new $k();
			$object->execute($query, $options);
		}
		return true;
	}
175612
public function query($query, array $params = null)
    {
        # If the next query should be cached then run the cache function instead
        if ($this->cacheNext) {
            $this->cacheNext = false;
            return $this->cache($query, $params);
        }

        # Ensure we have a connection to run this query on
        $this->connect();

        $this->query = $query;
        $this->params = null;
        $this->preparedQuery = false;

        if (is_array($params)) {
            $this->params = $params;
        }

        $this->quoteChars($query);
        $this->functions($query);
        $this->limit($query);
        $this->tableNames($query);
        $this->namedParams($query, $params);
        $this->paramArrays($query, $params);
        $this->convertNulls($params);

        $preparedQuery = $this->prepareQuery($query, $params);
        $this->preparedQuery = $preparedQuery;

        if ($this->output) {
            if ($this->htmlMode) {
                echo "<pre>";
            }

            echo $preparedQuery;

            if ($this->htmlMode) {
                echo "<hr>";
            } else {
                echo "\n";
            }
        }

        switch ($this->mode) {

            case "mysql":
                if (!$result = $this->server->query($preparedQuery)) {
                    $this->error();
                }
                break;

            case "postgres":
            case "redshift":
                $tmpQuery = $query;
                $query = "";

                $noParams = false;
                if ($this->mode == "redshift" && count($params) > 32767) {
                    $noParams = true;
                }

                $i = 1;
                reset($params);
                while ($pos = strpos($tmpQuery, "?")) {
                    if ($noParams) {
                        $query .= substr($tmpQuery, 0, $pos) . "'" . pg_escape_string(current($params)) . "'";
                        next($params);
                    } else {
                        $query .= substr($tmpQuery, 0, $pos) . "\$" . $i++;
                    }
                    $tmpQuery = substr($tmpQuery, $pos + 1);
                }
                $query .= $tmpQuery;

                $params = Helper::toArray($params);
                if (!$result = pg_query_params($this->server, $query, $params)) {
                    $this->error();
                }
                break;

            case "odbc":
                if (!$result = odbc_prepare($this->server, $query)) {
                    $this->error();
                }
                $params = Helper::toArray($params);
                if (!odbc_execute($result, $params)) {
                    $this->error();
                }
                break;

            case "sqlite":

                if (!is_array($params)) {
                    if (!$result = $this->server->query($preparedQuery)) {
                        $this->error();
                    }

                # If we have some parameters then we must convert them to the sqlite format
                } else {
                    $newQuery = "";
                    foreach ($params as $key => $val) {
                        $pos = strpos($query, "?");
                        $newQuery .= substr($query, 0, $pos);
                        $query = substr($query, $pos + 1);

                        $newQuery .= ":var" . $key;
                    }
                    $newQuery .= $query;

                    if (!$result = $this->server->prepare($newQuery)) {
                        $this->error();
                    }

                    foreach ($params as $key => $val) {
                        switch (gettype($val)) {

                            case "boolean":
                            case "integer":
                                $type = SQLITE3_INTEGER;
                                break;

                            case "double":
                                $type = SQLITE3_FLOAT;
                                break;

                            case "NULL":
                                if ($this->allowNulls) {
                                    $type = SQLITE3_NULL;
                                } else {
                                    $type = SQLITE3_TEXT;
                                    $val = "";
                                }
                                break;

                            default:
                                $type = SQLITE3_TEXT;
                        }

                        $result->bindValue(":var" . $key, $val, $type);
                    }

                    if (!$result = $result->execute()) {
                        $this->error();
                    }
                }
                break;

            case "mssql":
                if (!$result = mssql_query($preparedQuery, $this->server)) {
                    $this->error();
                }
                break;

            case "mssqlsrv":
                if (!$result = sqlsrv_query($this->server, $preparedQuery)) {
                    $this->error();
                }
        }

        if (!$result) {
            $this->error();
        }

        return new Result($result, $this->mode);
    }
1345329
private function _runQuery($query, $options)
    {
        $this->_testQueryStarts($query, '[select|show]');
        $statement = $this->_executeQuery($query, $options);
        if (is_object($statement) && $statement instanceof \PDOStatement) {
            return $statement;
        }
        else {
            $this->_error(FQDBException::INTERNAL_ASSERTION_FAIL, FQDBException::FQDB_CODE);
        }
    }
759298
public function query($query_with_placeholders, $named_parameters = []) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_QUERY, '', $named_parameters, $query_with_placeholders), $named_parameters);
            try {
                $stmt = $this->prepareStatement($query_with_placeholders, $named_parameters);
                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $query_with_placeholders, $named_parameters));
                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            Event::dispatch(EventData::forAfter(Event::AFTER_QUERY, null, $named_parameters, $query_with_placeholders, $stmt->rowCount()));

            return $this->fetch($stmt);
        }
1151075
protected function execQuery(array &$params, string &$query, int &$rowCount) : \PDOStatement
    {
        if (empty($params)) {
            $sth = $this->getConnection()->query($query);
        } else {
            $sth = $this->getConnection()->prepare($query);
            $sth->execute($params);
        }

        if (!$sth) {
            throw new QueryExecutionException();
        }

        $rowCount += $sth->rowCount();
        return $sth;
    }
537515
function execQueryString($sql, $params = null)
    {
        if (!is_array($params) && !is_null($params)) {
            $params = array($params);
        }

        $stmt = $this->prepare($sql);
        $stmt->execute($params);
        return $stmt;
    }
110461
public function query( SqlInterface $query, $options = 0 )
    {

        $options += $options & ( self::RECONNECT_AS_REQUIRED | self::RECONNECT_NO ) ? 0 : self::RECONNECT_DEFAULT;

        $this->numQuerys++;

        $timings = array();
        $timings['start'] = microtime( true );

        $sql = $query->parse( $this );
        $timings['query_parsed'] = microtime( true );

        $this->debug->emit( Debug::INFO, self::QUERY_PARSED, $sql );

        // debugging search path pest
        // $search_path = pg_query( $this->resource->get(), "SHOW search_path"); $result = pg_fetch_row( $search_path ); d_pr( $result );

        // set exception
        $resource = $this->resource->get( $options & self::RECONNECT_AS_REQUIRED );

        try {

            // really ghetto debuggin for when shit really hits the fan
            // file_put_contents( '~/sqllog.out', "{$sql}\n\n", FILE_APPEND );

            // execute query
            if( false === $result = @pg_query( $resource, $sql ) ) {
                throw new \Exception();
            }

        } catch( \Exception $e ) {

            $exceptionFactory = new QueryExceptionFactory( $resource, $sql, $this->debug );
            throw $exceptionFactory->get();

        }

        $timings['query_executed'] = microtime( true );
        $timings['total'] = $timings['query_executed'] - $timings['start'];
        $timings['parsing'] = $timings['query_parsed'] - $timings['start'];
        $timings['total'] = $timings['query_executed'] - $timings['query_parsed'];

        $this->debug->emit( self::QUERY_OK, $sql, $timings );

        $resultResourceObject = new Result( $result, $this, $query, $timings );

        return $resultResourceObject;

    }
1288454
public function query(string $sql, array $params = [])
    {
        $prepared = $this->prepare($sql, $params);
        $this->execute($prepared);
        return new ResultSet($prepared['statement']);
    }
962899
public function query($query, $options = [])
    {
        $url = $this->instanceURLRepo->get();
        $url .= $this->resourceRepo->get('query');
        $url .= '?q=';
        $url .= urlencode($query);

        $queryResults = $this->request($url, $options);

        return $queryResults;
    }
252129
public function query(string $sql, array $params = []): Statement
    {
        $this->usedPrepare = false;
        $stmt = $this->prepare($sql, $params);
        $this->usedPrepare = true;
        $stmt->execute();
        return $stmt;
    }
464685
public function executeQuery ($query, array $conditions = [], array $values = [], array $options = []) {
		//==============================================
		//IN句構築
		//==============================================
		$in_list = [];
		foreach ($conditions as $condition) {
			$column_value = current((array) $condition);
			if (is_array($column_value)) {
				$in_list[] = implode(', ', array_fill(0, count($column_value), '?'));
			}
		}

		if (!empty($in_list)) {
			$query = vsprintf($query, $in_list);
		}

		//==============================================
		//ステートメント構築
		//==============================================
		$stmt = $this->prepare($query);

		//もしもフェッチモード指定があった場合は設定
		if (isset($options[\PDO::ATTR_DEFAULT_FETCH_MODE])) {
			switch ($options[\PDO::ATTR_DEFAULT_FETCH_MODE]) {
				case \PDO::FETCH_LAZY:
				case \PDO::FETCH_ASSOC:
				case \PDO::FETCH_NAMED:
				case \PDO::FETCH_NUM:
				case \PDO::FETCH_BOTH:
				case \PDO::FETCH_OBJ:
				case \PDO::FETCH_BOUND:
				case \PDO::FETCH_FUNC:
				case \PDO::FETCH_GROUP:
				case \PDO::FETCH_UNIQUE:
				case \PDO::FETCH_KEY_PAIR:
				case \PDO::FETCH_CLASSTYPE:
				case \PDO::FETCH_SERIALIZE:
				case \PDO::FETCH_PROPS_LATE:
				case \PDO::FETCH_ORI_NEXT:
				case \PDO::FETCH_ORI_PRIOR:
				case \PDO::FETCH_ORI_FIRST:
				case \PDO::FETCH_ORI_LAST:
				case \PDO::FETCH_ORI_ABS:
				case \PDO::FETCH_ORI_REL:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE]);
					break;
				case \PDO::FETCH_COLUMN:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE], isset($options['colno']) ? $options['colno'] : 0);
					break;
				case \PDO::FETCH_CLASS:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE], isset($options['classname']) ? $options['classname'] : null, isset($options['ctorargs']) ? $options['ctorargs'] : null);
					break;
				case \PDO::FETCH_INTO:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE], isset($options['object']) ? $options['object'] : null);
					break;
			}
		}

		//==============================================
		//パラメータバインディング開始
		//==============================================
		//位置情報
		$i = 1;
/*
		//テーブル名取得
		$table_name = $options['table_name'] ?? null;

		//カラム情報
		$columns = $this->getColumns($table_name);

		//\PDO::PARAM_*リスト
		$pdo_param_list = static::GetPdoParamList();
*/
		//Update時のValueから先行してバインディングする
		foreach ($values as $column_name => $value) {
//			$stmt->bindValue($i++, $value, $pdo_param_list[$columns[$column_name]['Type']]);
			$stmt->bindValue($i++, $value);
		}

		//WHERE句以降のバインディング
		foreach ($conditions as $idx => $condition) {
			$condition = (array) $condition;
			$column_name = key($condition);
			$column_value = current($condition);

			if (is_array($column_value)) {
				foreach ($column_value as $value) {
					$stmt->bindValue($i++, $value);
				}
			} else {
				$stmt->bindValue($i++, $column_value);
			}
		}

		//==============================================
		//クエリ実行
		//==============================================
		try {
//@TODO mode setting
			$log_flag = false;
			if ($log_flag) {
				$execute_time = microtime(true);
			}

			$stmt->execute();
//@TODO mode setting
			if ($log_flag) {
				$execute_end_time = microtime(true);

				$parsed_execute_time = explode('.', $execute_time);

				$debug_dump_params = '';
				if ($log_flag) {
					ob_start();
					$stmt->debugDumpParams();
					$debug_dump_params = ob_get_clean();
				}

				$query_string = $stmt->queryString;

				$message = sprintf('[%s.%-4d] execute_time:%s query_string:%s dump:%s', date('Y-m-d H:i:s', $parsed_execute_time[0]), $parsed_execute_time[1], $execute_end_time - $execute_time, $query_string, $debug_dump_params);
//				StaticLog::WriteLog('sql_log', $message);
				print $message;
			}
		} catch (\PDOException $pdo_e) {
			$execute_end_time = microtime(true);

			$parsed_execute_time = explode('.', $execute_time);

			$error_info = $stmt->errorInfo();

//@TODO mode setting
			$debug_dump_params = '';
			if ($log_flag) {
				ob_start();
				$stmt->debugDumpParams();
				$debug_dump_params = ob_get_clean();
			}
			$query_string = $stmt->queryString;

			$message = sprintf(
					'[%s.%-4d] execute_time:%s SQLSTATE:%s code:%s message:%s query_string:%s dump:%s',
					date('Y-m-d H:i:s', $parsed_execute_time[0]),
					$parsed_execute_time[1],
					$execute_end_time - $execute_time,
					$error_info[0],
					$error_info[1],
					$error_info[2],
					$query_string,
					$debug_dump_params
			);

			StaticLog::WriteLog('sql_error', $message);

			throw $pdo_e;
		}

		//==============================================
		//処理の終了：PDOStatementクラスはTraversableを実装しているため、そのまま返してもforeachで利用できる。
		//==============================================
		return $stmt;
	}
201589
public function query($sql, $key = null, $options = []) {
		return $this->object->query($sql, $key, $options);
	}
609752
public function executeQuery($query, array $params = []) {
        $this->connect();

        $cacheKey = null;
        $cacheLength = null;

        // Determine cache key and lengths
        if ($query instanceof Query) {
            $cacheKey = $query->getCacheKey();
            $cacheLength = $query->getCacheLength();

        } else if (!is_string($query)) {
            throw new InvalidQueryException('Query must be a raw SQL string or a Titon\Db\Query instance');
        }

        // Execute and return result
        return $this->_result = $this->cacheQuery($cacheKey, function(AbstractPdoDriver $driver) use ($query, $params) {
            $isQuery = ($query instanceof Query);

            // Prepare statement and bind parameters
            if ($isQuery) {
                $statement = $driver->buildStatement($query);
                $binds = $driver->resolveParams($query);

            } else {
                $statement = $driver->getConnection()->prepare($query);
                $binds = [];

                foreach ($params as $value) {
                    $binds[] = [$value, $driver->resolveType($value)];
                }
            }

            foreach ($binds as $i => $value) {
                $statement->bindValue($i + 1, $value[0], $value[1]);
            }

            $statement->params = $binds;

            // Gather and log result
            if ($isQuery) {
                $result = new PdoResultSet($statement, $query);
            } else {
                $result = new PdoResultSet($statement);
            }

            $driver->logQuery($result);

            return $result;
        }, $cacheLength);
    }