Overview

Namespaces

  • DSchoenbauer
    • Sql
      • Command
      • Exception
      • Where

Classes

  • Create
  • Delete
  • Select
  • Update

Interfaces

  • CommandInterface

Traits

  • WhereTrait
  • Overview
  • Namespace
  • Class

Class Select

retrieves data from a PDO connected resource

DSchoenbauer\Sql\Command\Select implements DSchoenbauer\Sql\Command\CommandInterface uses DSchoenbauer\Sql\Command\WhereTrait
Namespace: DSchoenbauer\Sql\Command
Author: David Schoenbauer dschoenbauer@gmail.com
Located at Sql/Command/Select.php
Methods summary
public DSchoenbauer\Sql\Command\Select
# __construct( string $table, array $fields = [], DSchoenbauer\Sql\Where\WhereStatementInterface $where = null, integer $fetchStyle = DSchoenbauer\Sql\Command\PDO::FETCH_ASSOC, boolean $fetchFlat = false, mixed $defaultValue = [] )

retrieves data from a PDO connected resource

retrieves data from a PDO connected resource

Parameters

$table
name of the table that houses the data
$fields

optional default value: empty array - defines which fields are returned if no fields defined a star will be used

$where

optional default value: null - object used to limit the returned results

$fetchStyle

optional default value: PDO::FETCH_ASSOC - sets how the PDO statement will return records

$fetchFlat

optional default value: false - true will return one record, false will return all records

$defaultValue

optional default value: empty array - value to be returned on query failure

Returns

DSchoenbauer\Sql\Command\Select
the select object responsible for retrieving records

Since

v1.0.0
public mixed
# execute( PDO $pdo )

Runs a query and returns the result of the SQL

Runs a query and returns the result of the SQL

Parameters

$pdo
a PDO connection object

Returns

mixed
with return the result set as defined by fetchStyle

Throws

DSchoenbauer\Sql\Exception\ExecutionErrorException
on SQL error with the message of the exception

Since

v1.0.0

Implementation of

DSchoenbauer\Sql\Command\CommandInterface::execute()
protected boolean
# statementExecute( PDOStatement $stmt, array $whereData )

Runs the sql statement inserting the query's data

Runs the sql statement inserting the query's data

Parameters

$stmt
PDO statement of a prepared SQL statement
$whereData
data to be used to fill out a where statement

Returns

boolean
true query succeeds, false there was an error executing the query

Since

v1.0.0
protected array
# fetchData( PDOStatement $stmt, boolean $fetchFlat, integer $fetchStyle )

Fetches the data from PDO resource

Fetches the data from PDO resource

Parameters

$stmt
PDO statement of a prepared SQL statement
$fetchFlat
true returns one record, false returns all records
$fetchStyle

a \PDO::FETCH_* variable defining the format of the returned object

Returns

array
returns the results of the query

Since

v1.0.0
public string
# getSql( )

returns a PDO SQL string that has parameter syntax

returns a PDO SQL string that has parameter syntax

Returns

string

Since

v1.0.0

Implementation of

DSchoenbauer\Sql\Command\CommandInterface::getSql()
public DSchoenbauer\Sql\Command\Select
# setData( array $data )

acts as a cache to house ran queries

acts as a cache to house ran queries

Parameters

$data
data to be stored

Returns

DSchoenbauer\Sql\Command\Select
for method chaining

Since

v1.0.0
public mixed
# getData( )

Acts as a cache array that holds the data returned from a query

Acts as a cache array that holds the data returned from a query

Returns

mixed

Since

v1.0.0

Implementation of

DSchoenbauer\Sql\Command\CommandInterface::getData()
public string
# getTable( )

retrieves the table with which you wish to select from

retrieves the table with which you wish to select from

Returns

string
table with which you wish to select from

Since

v1.0.0
public DSchoenbauer\Sql\Command\Select
# setTable( string $table )

defines a table with which you wish to append to

defines a table with which you wish to append to

Parameters

$table
a table with which you wish to append to

Returns

DSchoenbauer\Sql\Command\Select
for method chaining

Since

v1.0.0
public array
# getFields( )

Returns the fields to be returned, if no fields defined all fields are returned

Returns the fields to be returned, if no fields defined all fields are returned

Returns

array

Since

v1.0.0
public DSchoenbauer\Sql\Command\Select
# setFields( array $fields = null )

Defines the fields to be returned, if no fields defined all fields are returned

Defines the fields to be returned, if no fields defined all fields are returned

Parameters

$fields

Returns

DSchoenbauer\Sql\Command\Select
for method chaining

Since

v1.0.0
public integer
# getFetchStyle( )

defines how data is returned

defines how data is returned

Returns

integer
$fetchStyle one of the PDO::FETCH_*

Since

v1.0.0
public DSchoenbauer\Sql\Command\Select
# setFetchStyle( integer $fetchStyle )

used to define how data is returned

used to define how data is returned

Parameters

$fetchStyle
one of the PDO::FETCH_*

Returns

DSchoenbauer\Sql\Command\Select
for method chaining

Since

v1.0.0
public boolean
# getFetchFlat( )

sets if one or many records will be returned.

sets if one or many records will be returned.

Returns

boolean
true for one record, false for all records

Since

v1.0.0
public DSchoenbauer\Sql\Command\Select
# setFetchFlat( boolean $fetchFlat = true )

sets if one or many records will be returned.

sets if one or many records will be returned.

Parameters

$fetchFlat

optional default value: false - true will return one record, false will return all records

Returns

DSchoenbauer\Sql\Command\Select
for method chaining

Since

v1.0.0
public mixed
# getDefaultValue( )

Value to be returned if no data is found or query fails

Value to be returned if no data is found or query fails

Returns

mixed
return the value used when the query returns false

Since

v1.0.0
public DSchoenbauer\Sql\Command\Select
# setDefaultValue( mixed $defaultValue = [] )

Value to be returned if no data is found or query fails

Value to be returned if no data is found or query fails

Parameters

$defaultValue

optional default value: empty array - value to be returned on query failure

Returns

DSchoenbauer\Sql\Command\Select
for method chaining

Since

v1.0.0
Methods used from DSchoenbauer\Sql\Command\WhereTrait
getWhere(), getWhereData(), getWhereStatement(), hasWhere(), setWhere()
API documentation generated by ApiGen