Overview
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();
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.
-
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.
-
compoundLimit()
-
Sets a compound limit count and offset to the query; used only in UNION (etc) queries.
-
compoundLimitPage()
-
Sets the compound limit and count by page number; used only in UNION (etc) queries.
-
compoundOrder()
-
Adds a compound row order to the query; used only in UNION (etc) queries.
-
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.
-
innerJoinSelect()
-
Adds an INNER JOIN sub-select 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.
-
leftJoinSelect()
-
Adds a LEFT JOIN sub-select 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.
-
multiJoin()
-
Adds multiple JOINs 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.
-
union()
-
Takes the current select properties and prepares them for UNION with the next set of select properties.
-
unionAll()
-
Takes the current select properties and prepares them for UNION ALL with the next set of select properties.
-
where()
-
Adds a WHERE condition to the query by AND.