|
Previous Class |
Solar_Sql_Select |
Next Page |
Solar_Sql_Select
Class for SQL select generation and results.
<?php
$select = Solar::factory('Solar_Sql_Select');
// select these columns from the 'contacts' table
$select->from('contacts', array(
'id',
'n_last',
'n_first',
'adr_street',
'adr_city',
'adr_region AS state',
'adr_postcode AS zip',
'adr_country',
));
// on these ANDed conditions
$select->where('n_last = :lastname');
$select->where('adr_city = :city');
// reverse-ordered by first name
$select->order('n_first DESC')
// get 50 per page, when we limit by page
$select->setPaging(50);
// bind data into the query.
// remember :lastname and :city in the where() calls above.
$data = ('lastname' => 'Jones', 'city' => 'Memphis');
$select->bind($data);
// limit by which page of results we want
$select->limitPage(1);
// get a PDOStatement object
$result = $select->fetchPdo();
// alternatively, get an array of all rows
$rows = $select->fetchAll();
// or an array of one row
$rows = $select->fetchOne();
// find out the count of rows, and how many pages there are.
// this comes back as an array('count' => ?, 'pages' => ?).
$total = $select->countPages();
?>
Catalog
This class is part of the Solar_Sql package.
Inheritance:
- Solar_Base
- Solar_Sql_Select
Constants
Public Properties
The Solar_Sql_Select class has no public properties; try the list of all properties.
Public Methods
These are all the public methods in the Solar_Sql_Select class.
You can also view the list of all public, protected, and private methods.
__construct()- Constructor.
__destruct()- Default destructor; does nothing other than provide a safe fallback for calls to parent::__destruct().
__toString()- Returns this object as an SQL statement string.
_multiHaving()- Backend support for multiHaving().
_multiWhere()- Backend support for multiWhere().
apiVersion()- Reports the API version for this class.
bind()- Adds data to bind into the query.
clear()- Clears query properties and row sources.
cols()- Adds 1 or more columns to the SELECT, without regard to a FROM or JOIN.
countPages()- Get the count of rows and number of pages for the current query.
distinct()- Makes the query SELECT DISTINCT.
dump()- Convenience method for getting a dump the whole object, or one of its properties, or an external variable.
fetch()- Fetch the results based on the current query properties.
fetchAll()- Fetches all rows from the database using sequential keys.
fetchAssoc()- Fetches all rows from the database using associative keys (defined by the first column).
fetchCol()- Fetches the first column of all rows as a sequential array.
fetchOne()- Fetches one row from the database.
fetchPairs()- Fetches an associative array of all rows as key-value pairs (first column is the key, second column is the value).
fetchPdo()- Fetches a PDOStatement result object.
fetchSql()- Builds the SQL statement and returns it as a string instead of executing it.
fetchValue()- Fetches the very first value (i.e., first column of the first row).
from()- Adds a FROM table and columns to the query.
fromSelect()- Adds a sub-select and columns to the query.
getPaging()- Gets the number of rows per page.
group()- Adds grouping to the query.
having()- Adds a HAVING condition to the query by AND.
innerJoin()- Adds an INNER JOIN table and columns to the query.
join()- Adds a JOIN table and columns to the query.
leftJoin()- Adds a LEFT JOIN table and columns to the query.
limit()- Sets a limit count and offset to the query.
limitPage()- Sets the limit and count by page number.
locale()- Looks up class-specific locale strings based on a key.
multiHaving()- Adds multiple HAVING conditions to the query.
multiWhere()- Adds multiple WHERE conditions to the query.
orHaving()- Adds a HAVING condition to the query by OR.
orWhere()- Adds a WHERE condition to the query by OR.
order()- Adds a row order to the query.
quote()- Safely quotes a value for an SQL statement.
quoteInto()- Quotes a value and places into a piece of text at a placeholder.
quoteMulti()- Quote multiple text-and-value pieces.
setPaging()- Sets the number of rows per page.
unbind()- Unsets bound data.
where()- Adds a WHERE condition to the query by AND.
Local
- Overview
- Constants
- Properties
- Methods
- __construct()
- __destruct()
- __toString()
- _addSource()
- _buildFrom()
- _buildJoin()
- _buildSelect()
- _countSubSelect()
- _exception()
- _hasCountCond()
- _join()
- _multiHaving()
- _multiWhere()
- _nameCols()
- _origAlias()
- apiVersion()
- bind()
- clear()
- cols()
- countPages()
- distinct()
- dump()
- fetch()
- fetchAll()
- fetchAssoc()
- fetchCol()
- fetchOne()
- fetchPairs()
- fetchPdo()
- fetchSql()
- fetchValue()
- from()
- fromSelect()
- getPaging()
- group()
- having()
- innerJoin()
- join()
- leftJoin()
- limit()
- limitPage()
- locale()
- multiHaving()
- multiWhere()
- orHaving()
- orWhere()
- order()
- quote()
- quoteInto()
- quoteMulti()
- setPaging()
- unbind()
- where()