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
Example #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());
 }
 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);
         }
     }
 }
Example #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;
 }
Example #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');
 }
Example #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'];
     }
 }
 /**
  * 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;
 }
Example #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());
 }
Example #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);
 }
 /**
  * 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);
 }
Example #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;
 }