select() public method

Run a select statement against the database.
public select ( string $query, array $bindings = [], boolean $useReadPdo = true ) : array
$query string
$bindings array
$useReadPdo boolean
return array
Exemplo n.º 1
0
 /**
  * Run the query as a "select" statement against the connection.
  *
  * @return array
  */
 protected function runSelect()
 {
     if ($this->useWritePdo) {
         return $this->connection->select($this->toSql(), $this->getBindings(), false);
     }
     return $this->connection->select($this->toSql(), $this->getBindings());
 }
Exemplo n.º 2
0
 private function _explainAndShowIndex(Connection $connection, $sql, $bindings)
 {
     $explainResults = $connection->select('explain ' . $sql, $bindings);
     foreach ($explainResults as $explainResult) {
         $results = get_object_vars($explainResult);
         $results['sql'] = $sql;
         $this->explainResults[] = $results;
         if (empty($results['table'])) {
             continue;
         }
         $showIndexResults = $connection->select('show index from ' . $results['table']);
         foreach ($showIndexResults as $showIndexResult) {
             $this->showIndexResults[] = get_object_vars($showIndexResult);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Process an "insert get ID" query for ODBC.
  *
  * @param  \Illuminate\Database\Connection  $connection
  * @return int
  */
 protected function processInsertGetIdForOdbc($connection)
 {
     $result = $connection->select('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid');
     if (!$result) {
         throw new Exception('Unable to retrieve lastInsertID for ODBC.');
     }
     return $result[0]->insertid;
 }
Exemplo n.º 4
0
 private function getTableColumns($callback = null)
 {
     if ($this->tableColumns === null) {
         $this->tableColumns = $this->db->select('SHOW COLUMNS FROM ' . $this->table);
     }
     $filteredColumns = $callback ? array_filter($this->tableColumns, $callback) : $this->tableColumns;
     return array_pluck($filteredColumns, 'Field');
 }
Exemplo n.º 5
0
 /**
  * Determine if any rows exist for the current query.
  *
  * @return bool
  */
 public function exists()
 {
     $sql = $this->grammar->compileExists($this);
     $results = $this->connection->select($sql, $this->getBindings(), !$this->useWritePdo);
     if (isset($results[0])) {
         $results = (array) $results[0];
         return (bool) $results['exists'];
     }
 }
Exemplo n.º 6
0
 /**
  * Execute the query as a "select" statement.
  *
  * @param  array  $columns
  * @return array
  */
 public function get($columns = array('*'))
 {
     // If no columns have been specified for the select statement, we will set them
     // here to either the passed columns, or the standard default of retrieving
     // all of the columns on the table using the "wildcard" column character.
     if (is_null($this->columns)) {
         $this->columns = $columns;
     }
     $results = $this->connection->select($this->toSql(), $this->bindings);
     $this->processor->processSelect($this, $results);
     return $results;
 }
Exemplo n.º 7
0
 /**
  * Run the query as a "select" statement against the connection.
  *
  * @return array
  */
 protected function runSelect()
 {
     return $this->connection->select($this->toSql(), $this->getBindings());
 }
Exemplo n.º 8
0
 /**
  * Get the column listing for a given table.
  *
  * @param  string  $table
  * @return array
  */
 public function getColumnListing($table)
 {
     $table = $this->connection->getTablePrefix() . $table;
     $results = $this->connection->select($this->grammar->compileColumnExists($table));
     return $this->connection->getPostProcessor()->processColumnListing($results);
 }
Exemplo n.º 9
0
 /**
  * Run a select statement against the database.
  *
  * @param  string  $query
  * @param  array   $bindings
  * @return \Stidges\LaravelDbNormalizer\Collection
  */
 public function select($query, $bindings = array())
 {
     $records = parent::select($query, $bindings);
     return $this->getNormalizer()->normalize($records);
 }
Exemplo n.º 10
0
 /**
  * Determine if the given table exists.
  *
  * @param  string  $table
  * @return bool
  */
 public function hasTable($table)
 {
     $sql = $this->grammar->compileTableExists();
     $table = $this->connection->getTablePrefix() . $table;
     return count($this->connection->select($sql, array($table))) > 0;
 }