Method:
select()
Class:
SQL
Method Call:
include_once("core/sql/SQL.php");
$db = new SQL();
ADODB_RECORDSET $db->select(ARRAY: $tables, ARRAY: $fields, [STRING: $condition]);
Description:
Execute a SELECT statement. If $fields contains an associative array (or arrays), then that inner array is treated as an alias and is
parsed by formatAlias().
Do not add backticks, single-quotes etc. - the SQL class will do this automatically depending on the database we're connected to as long as $fields is an ARRAY.
The return is an ADODB_RECORDSET suitable for passing to the fetchRow(), loopRecordSet() or fetchOne() methods etc. If it fails to execute the query, the script will exit with an error message.
Usage:
For example (assuming the database object exists within a class as $this->db):
$tables = array("WKX_resource"); $fields = array(array("WKX_resource.title" => "t"), "subtitle"); $condition = "WHERE " . $this->db->formatField('id') . "=" . $this->db->tidyInput(666); $recordset = $this->db->select($tables, $fields, $condition);In the above example the SELECT statement as formatted by select() before internally passing to query() will be:
SELECT `WKX_resource`.`title` AS `t`, `subtitle` FROM `WKX_resource` WHERE `id`='666';