Run a select statement against the database.

@param  string $query
@param  array $bindings
@param  bool $useReadPdo
@param  null | string $resultClass
@return array
542784
public function select( $query, $bindings = [ ], $useReadPdo = true, $resultClass = null )
	{
		$fetchCustomClass = ! is_null($resultClass) && class_exists($resultClass);

		return $this->run( $query, $bindings, function ( $query, $bindings ) use ( $useReadPdo, $fetchCustomClass, $resultClass ) {
			if( $this->pretending() )
			{
				return [];
			}

			// For select statements, we'll simply execute the query and return an array
			// of the database result set. Each element in the array will be a single
			// row from the database table, and will either be an array or objects.
			$statement = $this->prepared( $this->getPdoForSelect( $useReadPdo )->prepare( $query ), ! $fetchCustomClass );
			$this->bindValues( $statement, $this->prepareBindings( $bindings ) );
			$statement->execute();

			return $fetchCustomClass ? $statement->fetchAll(\PDO::FETCH_CLASS, $resultClass) : $statement->fetchAll();
		});
	}
26054
public function select($query, $bindings = [], $useReadPdo = true) {
    $types = [];

    $rows = $this->run($query, $bindings, function($query, $bindings) use($useReadPdo, &$types) {
      if($this->pretending()) {
        return [];
      }

      $statement = $this->getPdoForSelect($useReadPdo)->prepare($query);
      $statement->execute($this->prepareBindings($bindings));

      for($i = 0; $i < $statement->columnCount(); $i++) {
        $meta = $statement->getColumnMeta($i);

        if($meta !== false) {
          $type = $meta['native_type'];

          if(isset($meta['sqlite:decl_type'])) {
            if($meta['sqlite:decl_type'] === 'datetime') {
              $type = $meta['sqlite:decl_type'];
            }
          }

          $types[$meta['name']] = strtolower($type);
        }
      }

      return $statement->fetchAll(PDO::FETCH_ASSOC);
    });

    foreach($rows as &$row) {
      foreach($row as $col => &$value) {
        if($value !== null) {
          switch($types[$col]) {
            case 'long':
            case 'integer':
              $value = (int)$value;
            break;

            case 'double':
              $value = (float)$value;
            break;

            case 'timestamp':
            case 'datetime':
              if(strpos($value, '.') === false) {
                $value = strtotime($value);
              } else {
                $value = (float)DateTime::createFromFormat('Y-m-d H:i:s.u', $value)->format('U.u');
              }
            break;
          }
        }
      }
    }

    return $rows;
  }
809306
public function raw($query, array $bindings = array())
    {
        if (!empty($bindings)) {
            foreach ($bindings as $column => $value) {
                $this->bind($column, $value);
            }
        }

        $this->queryBuilder->raw($query);
        return $this;
    }
915575
public function exec($sql = "", $bindingValues = array(), $insert = true)
    {
        //Check if the query is a SELECT|INSERT|UPDATE and :variation is available
        if (preg_match("/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/", $sql)) {
            
            $this->sql = $sql;

            //Always prepare the SQL statement first
            $query = $this->connection->prepare($sql);

            if (preg_match('/\s*:(.+?)\s/', $sql)) {
                if (is_array($bindingValues) && !empty($bindingValues)) {
                    foreach ($bindingValues as $key => $val) {
                        //Clean the bindingValues. Check if they start with :
                        if (!preg_match('/:.*/', $key)) {
                            $bindingValues[":" . $key] = $val;
                            unset($bindingValues[$key]);
                        }
                    }
                }


                //Add the binding variables to the query
                if ($query->execute($bindingValues)) {
                    return $this->getLastInsertID();
                } else {
                    //@ToDo:When the save or update fails make sure we handle the error gracefully!
                    throw new \Exception(implode("\n", $query->errorInfo()));
                }

            } else {
                $result = $query->execute();
            }

            if (preg_match('/.*(SELECT|SHOW).*/', $sql)) {
                $query->setFetchMode(\PDO::FETCH_ASSOC);
                return $query->fetchAll();
            }

            return $result;
        }


        return false;
    }
742641
public function selectFromWriteConnection( $query, $bindings = [ ], $resultClass = null )
	{
		return $this->select( $query, $bindings, false, $resultClass );
	}
457332
public function statement($sql, $bindings = array())
    {
        $start = microtime(true);
        $pdoStatement = $this->pdo->prepare($sql);
        foreach ($bindings as $key => $value) {
            $pdoStatement->bindValue(
                is_int($key) ? $key + 1 : $key,
                $value,
                is_int($value) || is_bool($value) ? PDO::PARAM_INT : PDO::PARAM_STR
            );
        }
        $pdoStatement->execute();
        return array($pdoStatement, microtime(true) - $start);
    }
1264898
public function selectOne($query, $bindings = array())
    {
        $query .= " LIMIT 1;";
        $result = $this->select($query, $bindings);
        return (isset($result[0]) ? $result[0] : []);
    }
572387
function queryRow($query, $resultType = MYSQLI_ASSOC)
  {
    $res = $this->q($query);
    if ($res->num_rows == 0)
      $row = false;
    else
      $row = $res->fetch_array($resultType);
    $res->close();
    return $row;
  }
1309318
public function affectingStatement( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings, true );

		$result = $this->db->query( $new_query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $new_query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return intval( $result );
	}
426000
protected function run($query, $bindings, Closure $callback)
    {
        $this->reconnectIfMissingConnection();

        $start = microtime(true);

        try {
            $result = $this->runQueryCallback($query, $bindings, $callback);
        }
        catch (QueryException $e) {
            $result = $this->tryAgainIfCausedByLostConnection(
                $e, $query, $bindings, $callback
            );
        }

        $time = $this->getElapsedTime($start);

        $this->logQuery($query, $bindings, $time);

        return $result;
    }
365236
public function bindValues($query) {
        if (!empty($this->bind_values) && !empty($this->bind_keys)) {
            if (!$query instanceof \PDOStatement) {
                $this->setError('q', 'No valid PDO Statement provided');
            }

            for ($ii = 0; $ii < count($this->bind_values); $ii++) {
                $param = $this->get_PDO_param($this->bind_values[$ii]);
                $value = $this->bind_values[$ii];
                $key = $this->bind_keys[$ii];

                $query->bindValue($key, $value, $param);
            }
        }
    }
766146
protected function statement($query, $bindings = array())
    {
        $statement  = $this->getActivePdo()->prepare($query);

        return $statement->execute($bindings);
    }
1353159
public function statement($query, $bindings = [])
    {
        if (!empty($bindings)) {
            return $this->client->runQuery($query, ['arguments' => $bindings]);
        } else {
            return $this->client->runQuery($query);
        }
    }
1192435
protected function compileWherePart(Query $query, array &$bindings): string
    {
        $sql = $this->compileCriteria($query->where, $bindings);
        if ($sql !== '') {
            $sql = 'WHERE '.$sql;
        }

        return $sql;
    }
1336652
public function fromQuery($query, $bindings = [])
    {
        return $this->hydrate(
            $this->query->getConnection()->select($query, $bindings)
        );
    }
1350718
public function affectingStatement($query, $bindings = array())
	{
		return $this->run($query, $bindings, function($me, $query, $bindings)
		{
			if ($me->pretending()) return 0;

			// For update or delete statements, we want to get the number of rows affected
			// by the statement and return that back to the developer. We'll first need
			// to execute the statement and then we'll use PDO to fetch the affected.
			$statement = $me->getPdo()->prepare($query);

			$statement->execute($me->prepareBindings($bindings));

			return $statement->rowCount();
		});
	}
395212
protected function select(string $query, array $parameters = [], string $allowedTags = ""): array
    {
        if (!is_null($this->pager)) {
            $query .= $this->pager->getSqlLimit();
        }
        $statement = $this->query($query, $parameters);
        $statement->setAllowedHtmlTags($allowedTags);
        $results = [];
        while ($row = $statement->next($this->fetchStyle)) {
            $results[] = $row;
        }
        return $results;
    }