WIKINDX METHODS

Method:
selectWithExceptions()

Class:
SQL

Method Call:
include_once("core/sql/SQL.php");
$db = new SQL();
ADODB_RECORDSET $db->selectWithExceptions(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(). In this case, formatAlias() will scan for special strings and, if found, will not add backticks to the field name. It is used when a key in a $fields associative array is not a table field name but is actually a SQL function call. See the example below.

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.

Currently, the single exception is SQL's DATE_FORMAT function. Developers should edit ADODB::formatAliasWithExceptions() method to add more exceptions then edit this document.

Usage:
For example (assuming the database object exists within a class as $this->db):

	$recordset = $this->db->selectWithExceptions(array("WKX_news"), array(
			array($this->db->db->SQLDate('d/M/Y', 'timestamp') => 'timestamp'), 'title', 'news'), 
			'WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput('1'));
	$row = $this->db->fetchRow($recordset);
In the above example the SELECT statement as formatted by selectWithExceptions() before internally passing to query() will be:
	SELECT DATE_FORMAT(timestamp,'%d/%b/%Y') AS `timestamp`, `title`, `news` FROM `WKX_news` WHERE `id`='1';

The SQLDate() function is internal to ADOdb.

WIKINDX home      WIKINDX usage      WIKINDX classes